Problem when add new subclass of qt widget and promote to it
-
wrote on 10 Feb 2015, 03:50 last edited by
Dear All
I am new to qt and now I am about to use QOpenGLWidget for rendering scenes in qt. What I did is:
1. Add new c++ class MyGLWidget using the wizard and type the base class name as QOpenGLWidget (I can only manually type in the base class name as in the drop-down list theres no such option).
Then I only got a simple code snippet as below:
@class MyGLWidget : public QOpenGLWidget
{
public:
MyGLWidget();
~MyGLWidget();
};@2. I drag and add a QOpenGLWidget widget in the qt designer and promote to the MyGLWidget.
3. Complile and get error:ui_mainwindow.h:51: error: no matching function for call to 'MyGLWidget::MyGLWidget(QWidget*&)'
openGLWidget = new MyGLWidget(centralWidget);I have checked on the web and found that the new widget class should be like this:
@class MyGLWidget : public QOpenGLWidget
{
public:
MyGLWidget(QWidget *parent) : QOpenGLWidget(parent) { }
.....
}@My question is am I supposed to add this constructor manually everytime I add a new sub-widget? Did I miss something when add the class using the wizard? Is this the right way to do it? If it is, apart from the constructor, is there anything else should I manually add to the new class?
I am using qt5.4 on ubuntu 14.04 64bit.
Thanks all in advance.
Best regards,
dalishi -
wrote on 10 Feb 2015, 04:20 last edited by
Try not to mix problems.
Lets split them in 2:-
Promoting in designer works, but designer expects every widget
have Widget(QWidget *parent) constructor at least.
Sometimes it is Widget(QDialog *parent) , etc.
So problem is in 2. -
For some reason wizard did not create Widget(QWidget *parent) constructor.
I am not using Q5.4, but in 4.* wizards provided by Visual Studio addons add proper constructors if you derive your class from widget parents.
It is fairly possible that wizard does not know that QOpenGLWidget is actually a widget.
You may try to promote QWidget based class and see if it is a case.And in suchs case you might need to do it by hands until bug is reported and fixed.
Regards,
Alex -
-
wrote on 10 Feb 2015, 06:36 last edited by
did you add the include for QOpenGlWidget in your header file.
@#include <QOpenGLWidget>@
-
wrote on 10 Feb 2015, 07:00 last edited by
[quote author="alex_malyu" date="1423542029"]
You may try to promote QWidget based class and see if it is a case.And in suchs case you might need to do it by hands until bug is reported and fixed.
Regards,
Alex[/quote]
Hi Alex, you are right, I have tried to add a child class derived from the standard QWidget in the wizard and I got the expected results:
@class testQWidget : public QWidget
{
Q_OBJECT
public:
explicit testQWidget(QWidget *parent = 0);
~testQWidget();signals:
public slots:
};@I think for the time being I may have to manually modify my custom opengl widget.
Thanks for your kind help.
Best regards,
dalishi -
wrote on 10 Feb 2015, 07:02 last edited by
[quote author="euchkatzl" date="1423550211"]did you add the include for QOpenGlWidget in your header file.
@#include <QOpenGLWidget>@
[/quote]
Hi euchkatzl
Thanks for your reply. Yes, I have included the
@#include <QOpenGLWidget>@
Otherwise the complier will complain could not find the corrspoding classes.
1/5