Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem when add new subclass of qt widget and promote to it
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dalishi
    wrote on 10 Feb 2015, 03:50 last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on 10 Feb 2015, 04:20 last edited by
      #2

      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

      1 Reply Last reply
      0
      • E Offline
        E Offline
        euchkatzl
        wrote on 10 Feb 2015, 06:36 last edited by
        #3

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

        @#include <QOpenGLWidget>@

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dalishi
          wrote on 10 Feb 2015, 07:00 last edited by
          #4

          [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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dalishi
            wrote on 10 Feb 2015, 07:02 last edited by
            #5

            [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 Reply Last reply
            0

            1/5

            10 Feb 2015, 03:50

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved