Problem when add new subclass of qt widget and promote to it



  • 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



  • Try not to mix problems.
    Lets split them in 2:

    1. 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.

    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



  • did you add the include for QOpenGlWidget in your header file.

    @#include <QOpenGLWidget>@



  • [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



  • [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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.