Signal_draw in Gtkmm2.4 - c++

I'm trying to compile a gtkmm application that uses cairomm for drawing.
It compiles fine using gtkmm3.0 but when I try to compile it using gtkmm2.4 i get:
error: ‘signal_draw’ was not declared in this scope
I'm using g++.
It seems that there is no signal_draw in gtkmm2.4(Am I wrong?). Is there any function/signal that can be used instead?
Thanks in advance.
Sorry for my bad English.
Some code:
class egclass: public Gtk::DrawingArea
{
public:
egclass();
virtual ~egclass();
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
};
egclass::egclass()
{
#ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
signal_draw().connect(sigc::mem_fun(*this, &egclass::on_draw), false);
#endif
}

The older gtkmm 2.4 has on_expose_event instead:
virtual bool on_expose_event(GdkEventExpose* event);
If you need to create a cairo context for drawing, with the GTK+ C API it goes something like this:
cairo_t *cr;
cr = gdk_cairo_create (event->window);
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
/* do your drawing */
cairo_destroy (cr);
... translating the snippet above to gtkmm is left as an exercise to the reader.
Also see the following links:
Porting from gtkmm-2.4 to gtkmm-3.0
Migrating from GTK+ 2.x to GTK+ 3
example_pixbufs.cc

Related

Using glad in Qt: QOpenGL and glad are conflicting

QT version: 5.12.0
OpenGL version: 4.5 core
Development environment: VS 2017
pro file:
QT += widgets
...
I have already add the glad.c file into my project, and ensure that the glad.h is included at the first place in every file.
But while I compile my project, all the other classes that using OpenGL functions are normal, except the class inherited from QOpenGLWidget.
MappingView.h
#include <glad/glad.h>
...
class MappingView : public QOpenGLWidget {
Q_OBJECT
public:
MappingView(QWidget * parent = nullptr);
~MappingView();
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
...
GLuint m_pointer_texture;
}
MappingView.cpp
MappingView::MappingView(QWidget * parent) : QOpenGLWidget(parent) {
}
MappingView::~MappingView() {
glDeleteTextures(1, &m_pointer_texture);
}
void MappingView::initializeGL() {
// load glad
if (!gladLoadGL()) {
return;
}
glGenTextures(1, &m_pointer_texture);
}
Compile error: C3861, cann't find glDeleteTextures.
When I click to the definition of glDeleteTextures in VS, it will jump to QOpenGLFunctions, but not glad.h. It seems that the OpenGL in QT and glad is conflicting. But my project doesn't use QOpenGLFunctions.
When I try to add a macro in MappingView.h,
#define QT_NO_OPENGL
all OpenGL functions in MappingView can be successfully found in glad.h, but the base class QOpenGLWidget cannot be found instead, which means that the MappingView class cannot be inherited from QOpenGLWidget any more.
I would be very appreciated if somebody could help me to resolve the problem, thanks!

No member named 'setMargin' in 'QwtPlotLayout' - Convert Qt4.7 to Qt5.8

I need to convert Qt legacy code from 4.7 to 5.8, I have a compilation error in Qt Creator 4.2.1 Clang 7.0(Apple) 64bit. I'm using latest Qwt 6.1.3
Looking in .cpp file
#include "frmMainChart_UI.h"
#include <QHeaderView>
#include <qwt_plot_layout.h>
#include <qwt_legend.h>
#include "mpiDateScale.h"
#include "mpiPercentScale.h"
void frmMainChart_UI::setupUI(QWidget *parent_)
{
frmMainTableViewTree_UI::setupUI(QMap<int, QString>(), false, parent_);
delete frmMainTableViewTree_UI::tableCopy;
delete frmMainTableViewTree_UI::table;
chart = new mpiChart(widget);
chart->setAxisScaleDraw(QwtPlot::xBottom, new mpiDateScale());
chart->setAxisScaleDraw(QwtPlot::yLeft, new mpiPercentScale());
chart->plotLayout()->setCanvasMargin(20);
chart->plotLayout()->setMargin(20); // BROKE convert Qt4 to Qt5
chartZoomer = new mpiPlotZoomer(chart->canvas()); // BROKE convert Qt4 to Qt5
chartLegend = new QwtLegend(chart);
chart->insertLegend(chartLegend, QwtPlot::RightLegend);
QLinearGradient grad(0, 0, 1, 1);
grad.setCoordinateMode(QGradient::StretchToDeviceMode);
grad.setColorAt(0, Qt::white);
grad.setColorAt(1, QColor(220, 220, 220));
2 Errors in .cpp
../src/ui/frmMainChart_UI.cpp:18:26: error: no member named 'setMargin' in 'QwtPlotLayout'
chart->plotLayout()->setMargin(20); // BROKE convert Qt4 to Qt5
../src/ui/frmMainChart_UI.cpp:19:23: error: no matching constructor for initialization of 'mpiPlotZoomer'
chartZoomer = new mpiPlotZoomer(chart->canvas()); // BROKE convert Qt4 to Qt5
^
5 warnings and 2 errors generated
make: *** [frmMainChart_UI.o] Error 1
06:58:25: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project mypersonalindex (kit: Desktop Qt 5.8.0 clang 64bit)
When executing step "Make"
06:58:25: Elapsed time: 00:01.
The Qwt 6.1.3 Docs has member function http://qwt.sourceforge.net/class_qwt_plot_layout.html
void setCanvasMargin (int margin, int axis=-1)
But NO Member Function being used
setMargin
My C++ skill is pretty limited, do you see any minor tweaks that could convert this from Qt4 to Qt5. ... so what is the replacement?
Looking at mpiChart.h likely relates to canvas() error
#ifndef MPICHART_H
#define MPICHART_H
#include "qwt_plot.h"
class mpiChart : public QwtPlot
{
Q_OBJECT
public:
mpiChart(QWidget *parent_ = 0):
QwtPlot(parent_)
{}
public slots:
void exportChart();
};
#endif // MPICHART_H
And Looking in mpiPlotZoomer.h relates to canvas() error
#ifndef MPIPLOTZOOMER_H
#define MPIPLOTZOOMER_H
#include <qwt_plot_zoomer.h>
#include <qwt_plot_canvas.h> // JDL convert Qt4 to Qt5
#include <qwt_compat.h> // JDL convert Qt4 to Qt5
class mpiPlotZoomer: public QwtPlotZoomer
{
public:
mpiPlotZoomer(QwtPlotCanvas *canvas_):
QwtPlotZoomer(canvas_, false)
{
setTrackerMode(AlwaysOn);
}
virtual QwtText trackerText(const QwtDoublePoint &pos_) const;
};
#endif // MPIPLOTZOOMER_H
As the setMargin function has been removed between Qwt version you were using for Qt 4.7 and Qwt 1.6.3 you are using with 5.8, you have no other choice than:
Replace setMargin calls by setCanvasMargin if that fits your needs
Or, remove setMargin calls
Try both, and see which one looks the best when displaying the GUI.
For the canvas() error, it's hard to tell without seeing mpiChart and mpiPlotZoomer declaration. However, I'll give it a try:
canvas() used to return a QwtPlotCanvas* in the past. For recent versions of Qwt it returns a QWidget*. So if your mpiPlotZoomer constructor expects a QwtPlotCanvas* as parameter, you'll have to:
Replace mpiPlotZoomer parameters type from QwtPlotCanvas* by QWidget*. May work if the guy who wrote the mpiPlotZoomer class does not actually use and QwtPlotCanvas members/attributes (he may only use it for parenting purpose)
Or replace mpiPlotZoomer(chart->canvas()); by mpiPlotZoomer( qobject_cast<QwtPlotCanvas*>( chart->canvas() ) ); which will hoepfully work fine.

Qt5, Ubuntu. Failure in building an app with Opengl

I'm a novice in Qt5, want to make a simple programm with interactive 3D graphics. I create a new Qt Widgets app, following manuals I do QT += opengl in .pro, #include<QtOpenGL> in .h, and that's all. I even don't add any extra code, I click "build project" and get this:
/opt/qtsdk/5.5/gcc/include/QtGui/qopenglext.h:117: ошибка: typedef
'PFNGLDRAWRANGEELEMENTSPROC' is initialized (use decltype instead)
typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode,
GLuint start, GLuint end, GLsizei count, GLenum type, const void
*indices); 'GLenum' was not declared in this scope 'GLuint' was not declared in this scope 'GLsizei' was not declared in this scope
'GLenum' was not declared in this scope expected primary-expression
before 'const' typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC)
(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type,
const void *indices); typedef 'PFNGLTEXIMAGE3DPROC' is initialized
(use decltype instead) typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC)
(GLenum target, GLint level, GLint internalformat, GLsizei width,
GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum
type, const void *pixels);
and same on and on till I stop building as I get the 8140th error, which isn't the last. :\
Please, help!! Tried everything, can't take it anymore
I installed Qt5 (lib and IDE together) by online-installation, then tried to fix them:
$ apt-get install libgl1-mesa-dev
$ sudo aptitude install mesa-common-dev
$ sudo apt-get install build-essential libfontconfig1
etc. Tried everything, that managed to find regarding my problem (though google says nothig useful solving exactly my problem)
OS: Linux Mint 17.1 Cinnamon 32bit
Video card: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (Total crap. Maybe, that's an issue?)
OpenGL version: 3.0 Mesa 10.1.3 (Does QtOpengl use a default Оpengl, preinstalled on my laptop, or uses its own Opengl? Though, how do versions of Opengl and Qt correlate? Would Qt4-5 even work witn an old Opengl version?)
Qt version: 4.8.6 (At least console says so, but I'm not shure that projects aren't built with Qt5 libs. How can I explicitly specify the version I need to build the project by the way?)
Auto-detected Qt version: Desktop Qt 5.5.1 GCC 32bit
QMake version: 2.01a
Auto-detected compiler: GCC; debugger: GDB
Need your help very much! Thanks
The only code I have:
That's mainscene.h:
#ifndef MAINSCENE_H
#define MAINSCENE_H
#include <QMainWindow>
#include<QtOpenGL>
#include<QGLWidget>
class MainScene : public QMainWindow
{
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
public:
Scene3D(QWidget* parent = 0);
};
#endif // MAINSCENE_H
That's the SimpleOpengl.pro:
QT += core gui
QT += opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SimpleOpengl
TEMPLATE = app
SOURCES += main.cpp
mainscene.cpp
HEADERS += mainscene.h
That's the main.cpp:
#include "mainscene.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainScene w;
w.show();
return a.exec();
}
(It's all wrong, isn't it?..)

Cocos2d-x 3.7 C++ CCLoad UIPageView crashing

This happens on all platforms but this description is for iPhone 5s 8.4 simulator, through the Xcode.
I have been working on the game using C++ and cocos2d-x version 3.6 and Cocostudio 2.3.1. All was fine until i updated to the official release of cocos 3.7. App started getting crashes. One of those is particularly interesting regarding UIPageView. So my header and cpp files are like that:
MKEpochSelectionScene.h
#include "cocos2d.h"
#include "cocos-ext.h"
#include <cocos/ui/CocosGUI.h>
class MKEpochSelectionScene : public cocos2d::Scene {
public:
bool init();
CREATE_FUNC(MKEpochSelectionScene);
private:
cocos2d::ui::PageView * mainPageView;
void previousEpoch(Ref* pSender, cocos2d::ui::Widget::TouchEventType eEventType);
void nextEpoch(Ref* pSender, cocos2d::ui::Widget::TouchEventType eEventType);
void showEpoch(Ref* pSender, cocos2d::ui::Widget::TouchEventType eEventType);
};
MKEpochSelectionScene.cpp
#include "MKEpochSelectionScene.h"
#include <editor-support/cocostudio/CocoStudio.h>
#include "MKGameScene.h"
#include "MKLevelSelectionScene.h"
USING_NS_CC;
bool MKEpochSelectionScene::init()
{
if(!Scene::init()) return false;
auto node = CSLoader::createNode("UI/Epoch/Layer.csb");
this->addChild(node);
auto buttonLeft = node->getChildByName<ui::Button *>("Button_Left");
CCASSERT(buttonLeft != nullptr, "Button left is null");
buttonLeft->addTouchEventListener(CC_CALLBACK_2(MKEpochSelectionScene::nextEpoch,this));
auto buttonRight = node->getChildByName<ui::Button *>("Button_Right");
CCASSERT(buttonRight != nullptr, "Button right is null");
buttonRight->addTouchEventListener(CC_CALLBACK_2(MKEpochSelectionScene::previousEpoch,this));
//******CRASHING LINE
mainPageView = (cocos2d::ui::PageView *)node->getChildByName("selectEpoch");
//******CRASHING LINE
CCASSERT(mainPageView != nullptr, "Main pageview is nil");
CCASSERT(mainPageView->getPages().size() > 0, "Page view has zero pages");
return true;
}
//Other methods
//....
}
Sooo.... The thing happens with the mainPageView. Crash occurs on the line where i reference UIPageView from the design file and assign it to the mainPageView ivar. Crash does not say anything, but crashes in the NavMesh file at the following:
So it crashes when i try to pushscene as to switch to this scene from mainMenu. There is one more thing... If i use local variable like: auto mainPageView instead of ivar in the init() method, it does not crash. And if i comment the UIPageView referencing at all e.g. crashing line - it does not crash.
What i have tried: Updated Cocostudio to 2.3.1.1 which is the latest. Republished all of the UI using that new version. Cleaned all caches and stuff of the build. Updates to the new cocos engine version by creating new project with the new version and copying over files from the old version and importing into the project. This is just to say that i have tried several things.
Any help would be appreciated. And i am sure this might be a silly mistake of mine...
Cheers!
I think you are triggering this bug:
https://github.com/cocos2d/cocos2d-x/issues/12962
It is going to fixed in v3.7.1

Why doesn't my Qt Creator know QPolygon?

I have the following simple code. I just start writing my application and get stuck on this problem: Qt Creator tells me, that QPolygon file or directory doesn't exists. I checked it with QT Documentation and it says, ther is.
#include <QPolygon>
class IHledani
{
public:
virtual IHledani();
virtual ~IHledani();
virtual QPolygon najdiKonturu(IObraz image, int startx, int starty);
};
Thank you