Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Designer Generated header invoking default ctor
QtWS25 Last Chance

Designer Generated header invoking default ctor

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
6 Posts 3 Posters 230 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I've got a class called ImageViewer that sub-classes QWidget.

    I've promoted a QWidget to an ImageViewer.

    The code generated looks like:

            tabWidget = new QTabWidget(DeepSkyStackerLive);
            tabWidget->setObjectName("tabWidget");
            tabWidget->setMinimumSize(QSize(730, 598));
            tabWidget->setMaximumSize(QSize(16777215, 16777215));
            stackedImage = new ImageViewer();
            stackedImage->setObjectName("stackedImage");
    

    I expected to see

    stackedImage = new ImageViewer(DeepSkyStackerLive);

    What have I failed to do?

    JonBJ 1 Reply Last reply
    0
    • PerdrixP Perdrix

      I've got a class called ImageViewer that sub-classes QWidget.

      I've promoted a QWidget to an ImageViewer.

      The code generated looks like:

              tabWidget = new QTabWidget(DeepSkyStackerLive);
              tabWidget->setObjectName("tabWidget");
              tabWidget->setMinimumSize(QSize(730, 598));
              tabWidget->setMaximumSize(QSize(16777215, 16777215));
              stackedImage = new ImageViewer();
              stackedImage->setObjectName("stackedImage");
      

      I expected to see

      stackedImage = new ImageViewer(DeepSkyStackerLive);

      What have I failed to do?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Perdrix
      Let's just start with: whatever DeepSkyStackerLive is, it appears you have laid the QTabWidget on it as a child. Have you done the same for ImageViewer, do they both show in the same place with the same parent in the hierarchy?

      Also just check that the generated code does not have setParent() explicitly somewhere? Or even if stackedImage gets added to a layout?

      If you run the program, at runtime what does stackedImage->parent() actually report?

      PerdrixP 1 Reply Last reply
      0
      • JonBJ JonB

        @Perdrix
        Let's just start with: whatever DeepSkyStackerLive is, it appears you have laid the QTabWidget on it as a child. Have you done the same for ImageViewer, do they both show in the same place with the same parent in the hierarchy?

        Also just check that the generated code does not have setParent() explicitly somewhere? Or even if stackedImage gets added to a layout?

        If you run the program, at runtime what does stackedImage->parent() actually report?

        PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by Perdrix
        #3

        @JonB Code won't even compile because the only ctor for ImageViewer is:

        ImageViewer(QWidget* parent);

        The ui file starts like this:

        <?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0">
         <class>DeepSkyStackerLive</class>
         <widget class="QWidget" name="DeepSkyStackerLive">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>0</y>
            <width>816</width>
            <height>748</height>
           </rect>
          </property>
          <property name="minimumSize">
           <size>
            <width>757</width>
            <height>748</height>
           </size>
          </property>
          <property name="windowTitle">
           <string>Form</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout_4">
           <item>
            <widget class="QWidget" name="widget_2" native="true">
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>126</height>
              </size>
             </property>
             <property name="styleSheet">
              <string notr="true">background: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(138, 185, 242, 0), stop:1 rgba(138, 185, 242, 255))</string>
             </property>
             <layout class="QVBoxLayout" name="verticalLayout_2">
              <item>
               <layout class="QHBoxLayout" name="horizontalLayout">
                <item>
                 <widget class="QLabel" name="monitorText">
                  <property name="sizePolicy">
                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
                    <horstretch>0</horstretch>
                    <verstretch>0</verstretch>
                   </sizepolicy>
                  </property>
                  <property name="styleSheet">
                   <string notr="true">background: qcolor(rgba(0,0,0,0))</string>
                  </property>
                  <property name="text">
                   <string comment="IDC_MONITORINGRECT">Monitoring</string>
                  </property>
                 </widget>
                </item>
                <item>
                 <widget class="QLabel" name="folderName">
                  <property name="styleSheet">
                   <string notr="true">background: qcolor(rgba(0,0,0,0))</string>
                  </property>
                  <property name="text">
                   <string comment="IDC_MONITOREDFOLDER"><Click here to select the Monitored Folder></string>
                  </property>
                 </widget>
                </item>
                <item>
                 <spacer name="horizontalSpacer_2">
                  <property name="orientation">
                   <enum>Qt::Horizontal</enum>
                  </property>
                  <property name="sizeHint" stdset="0">
                   <size>
                    <width>40</width>
                    <height>20</height>
                   </size>
                  </property>
                 </spacer>
                </item>
               </layout>
              </item>
              <item>
               <layout class="QHBoxLayout" name="horizontalLayout_3">
                <item>
                 <widget class="QToolBar" name="toolbar">
                  <property name="sizePolicy">
                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
                    <horstretch>0</horstretch>
                    <verstretch>0</verstretch>
                   </sizepolicy>
                  </property>
                  <property name="minimumSize">
                   <size>
                    <width>0</width>
                    <height>0</height>
                   </size>
                  </property>
                  <property name="styleSheet">
                   <string notr="true">background: qcolor(rgba(0,0,0,0))</string>
                  </property>
                  <property name="movable">
                   <bool>false</bool>
                  </property>
                  <property name="iconSize">
                   <size>
                    <width>48</width>
                    <height>48</height>
                   </size>
                  </property>
                  <property name="toolButtonStyle">
                   <enum>Qt::ToolButtonTextUnderIcon</enum>
                  </property>
                  <property name="floatable">
                   <bool>false</bool>
                  </property>
                  <addaction name="actionMonitor"/>
                  <addaction name="actionStack"/>
                  <addaction name="actionStop"/>
                 </widget>
                </item>
                <item>
                 <layout class="QVBoxLayout" name="verticalLayout">
                  <item>
                   <spacer name="verticalSpacer_1">
                    <property name="orientation">
                     <enum>Qt::Vertical</enum>
                    </property>
                    <property name="sizeType">
                     <enum>QSizePolicy::Fixed</enum>
                    </property>
                    <property name="sizeHint" stdset="0">
                     <size>
                      <width>20</width>
                      <height>13</height>
                     </size>
                    </property>
                   </spacer>
                  </item>
                  <item>
                   <widget class="QProgressBar" name="progressBar">
                    <property name="value">
                     <number>24</number>
                    </property>
                   </widget>
                  </item>
                  <item>
                   <widget class="QLabel" name="status">
                    <property name="sizePolicy">
                     <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
                      <horstretch>0</horstretch>
                      <verstretch>0</verstretch>
                     </sizepolicy>
                    </property>
                    <property name="text">
                     <string comment="IDC_STATS">Pending: %ld - Registered: %ld - Stacked: %ld - Total exposure time: %s</string>
                    </property>
                   </widget>
                  </item>
                 </layout>
                </item>
               </layout>
              </item>
             </layout>
            </widget>
           </item>
           <item>
            <widget class="QTabWidget" name="tabWidget">
             <property name="minimumSize">
              <size>
               <width>730</width>
               <height>598</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>16777215</height>
              </size>
             </property>
             <property name="currentIndex">
              <number>1</number>
             </property>
             <widget class="ImageViewer" name="stackedImage">
              <property name="sizePolicy">
               <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
                <horstretch>0</horstretch>
                <verstretch>0</verstretch>
               </sizepolicy>
              </property>
              <attribute name="title">
               <string comment="IDC_STACKEDIMAGE">Stacked Image</string>
              </attribute>
             </widget>
        

        All the controls are created as children of DeepSkyStackerLive except for stackedImage and lastImage which the ui header file tries to create using a default ctor.

        JonBJ 1 Reply Last reply
        0
        • PerdrixP Perdrix

          @JonB Code won't even compile because the only ctor for ImageViewer is:

          ImageViewer(QWidget* parent);

          The ui file starts like this:

          <?xml version="1.0" encoding="UTF-8"?>
          <ui version="4.0">
           <class>DeepSkyStackerLive</class>
           <widget class="QWidget" name="DeepSkyStackerLive">
            <property name="geometry">
             <rect>
              <x>0</x>
              <y>0</y>
              <width>816</width>
              <height>748</height>
             </rect>
            </property>
            <property name="minimumSize">
             <size>
              <width>757</width>
              <height>748</height>
             </size>
            </property>
            <property name="windowTitle">
             <string>Form</string>
            </property>
            <layout class="QVBoxLayout" name="verticalLayout_4">
             <item>
              <widget class="QWidget" name="widget_2" native="true">
               <property name="maximumSize">
                <size>
                 <width>16777215</width>
                 <height>126</height>
                </size>
               </property>
               <property name="styleSheet">
                <string notr="true">background: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(138, 185, 242, 0), stop:1 rgba(138, 185, 242, 255))</string>
               </property>
               <layout class="QVBoxLayout" name="verticalLayout_2">
                <item>
                 <layout class="QHBoxLayout" name="horizontalLayout">
                  <item>
                   <widget class="QLabel" name="monitorText">
                    <property name="sizePolicy">
                     <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
                      <horstretch>0</horstretch>
                      <verstretch>0</verstretch>
                     </sizepolicy>
                    </property>
                    <property name="styleSheet">
                     <string notr="true">background: qcolor(rgba(0,0,0,0))</string>
                    </property>
                    <property name="text">
                     <string comment="IDC_MONITORINGRECT">Monitoring</string>
                    </property>
                   </widget>
                  </item>
                  <item>
                   <widget class="QLabel" name="folderName">
                    <property name="styleSheet">
                     <string notr="true">background: qcolor(rgba(0,0,0,0))</string>
                    </property>
                    <property name="text">
                     <string comment="IDC_MONITOREDFOLDER"><Click here to select the Monitored Folder></string>
                    </property>
                   </widget>
                  </item>
                  <item>
                   <spacer name="horizontalSpacer_2">
                    <property name="orientation">
                     <enum>Qt::Horizontal</enum>
                    </property>
                    <property name="sizeHint" stdset="0">
                     <size>
                      <width>40</width>
                      <height>20</height>
                     </size>
                    </property>
                   </spacer>
                  </item>
                 </layout>
                </item>
                <item>
                 <layout class="QHBoxLayout" name="horizontalLayout_3">
                  <item>
                   <widget class="QToolBar" name="toolbar">
                    <property name="sizePolicy">
                     <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
                      <horstretch>0</horstretch>
                      <verstretch>0</verstretch>
                     </sizepolicy>
                    </property>
                    <property name="minimumSize">
                     <size>
                      <width>0</width>
                      <height>0</height>
                     </size>
                    </property>
                    <property name="styleSheet">
                     <string notr="true">background: qcolor(rgba(0,0,0,0))</string>
                    </property>
                    <property name="movable">
                     <bool>false</bool>
                    </property>
                    <property name="iconSize">
                     <size>
                      <width>48</width>
                      <height>48</height>
                     </size>
                    </property>
                    <property name="toolButtonStyle">
                     <enum>Qt::ToolButtonTextUnderIcon</enum>
                    </property>
                    <property name="floatable">
                     <bool>false</bool>
                    </property>
                    <addaction name="actionMonitor"/>
                    <addaction name="actionStack"/>
                    <addaction name="actionStop"/>
                   </widget>
                  </item>
                  <item>
                   <layout class="QVBoxLayout" name="verticalLayout">
                    <item>
                     <spacer name="verticalSpacer_1">
                      <property name="orientation">
                       <enum>Qt::Vertical</enum>
                      </property>
                      <property name="sizeType">
                       <enum>QSizePolicy::Fixed</enum>
                      </property>
                      <property name="sizeHint" stdset="0">
                       <size>
                        <width>20</width>
                        <height>13</height>
                       </size>
                      </property>
                     </spacer>
                    </item>
                    <item>
                     <widget class="QProgressBar" name="progressBar">
                      <property name="value">
                       <number>24</number>
                      </property>
                     </widget>
                    </item>
                    <item>
                     <widget class="QLabel" name="status">
                      <property name="sizePolicy">
                       <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
                        <horstretch>0</horstretch>
                        <verstretch>0</verstretch>
                       </sizepolicy>
                      </property>
                      <property name="text">
                       <string comment="IDC_STATS">Pending: %ld - Registered: %ld - Stacked: %ld - Total exposure time: %s</string>
                      </property>
                     </widget>
                    </item>
                   </layout>
                  </item>
                 </layout>
                </item>
               </layout>
              </widget>
             </item>
             <item>
              <widget class="QTabWidget" name="tabWidget">
               <property name="minimumSize">
                <size>
                 <width>730</width>
                 <height>598</height>
                </size>
               </property>
               <property name="maximumSize">
                <size>
                 <width>16777215</width>
                 <height>16777215</height>
                </size>
               </property>
               <property name="currentIndex">
                <number>1</number>
               </property>
               <widget class="ImageViewer" name="stackedImage">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <attribute name="title">
                 <string comment="IDC_STACKEDIMAGE">Stacked Image</string>
                </attribute>
               </widget>
          

          All the controls are created as children of DeepSkyStackerLive except for stackedImage and lastImage which the ui header file tries to create using a default ctor.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Perdrix
          I have never used promotion. I would have expected the generated file would have as constructor signature ImageViewer(QWidget* parent = nullptr).

          So far as I can see from your .ui, your ImageViewer is actually placed on/a child of the QTabWidget, not the DeepSkyStackerLive. Plus I thought QTabWidget would have its "pages" as some kind of <item>, but I'm not sure.

          Make of it as you will. I would probably re-start with just the promoted widget on a plain, simple UI, eliminate the QTabWidget and anything else while you just get it going/reproduce a problem.

          PerdrixP 1 Reply Last reply
          0
          • JonBJ JonB

            @Perdrix
            I have never used promotion. I would have expected the generated file would have as constructor signature ImageViewer(QWidget* parent = nullptr).

            So far as I can see from your .ui, your ImageViewer is actually placed on/a child of the QTabWidget, not the DeepSkyStackerLive. Plus I thought QTabWidget would have its "pages" as some kind of <item>, but I'm not sure.

            Make of it as you will. I would probably re-start with just the promoted widget on a plain, simple UI, eliminate the QTabWidget and anything else while you just get it going/reproduce a problem.

            PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by Perdrix
            #5

            @JonB I have another ui that is very similar, but doesn't use a tab widget. That one works just fine.

            The problem appears to be that the QWidgets that make up each tab are constructed in the ui_classname.h file using a default ctor which sort of feels "Wrong".

            I think the assumption is that as QTabWidget::addTab will reparent the control it's OK to use a default ctor!

            I'll add a default ctor to my class

            S 1 Reply Last reply
            0
            • PerdrixP Perdrix

              @JonB I have another ui that is very similar, but doesn't use a tab widget. That one works just fine.

              The problem appears to be that the QWidgets that make up each tab are constructed in the ui_classname.h file using a default ctor which sort of feels "Wrong".

              I think the assumption is that as QTabWidget::addTab will reparent the control it's OK to use a default ctor!

              I'll add a default ctor to my class

              S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #6

              @Perdrix said in Designer Generated header invoking default ctor:

              I think the assumption is that as QTabWidget::addTab will reparent the control it's OK to use a default ctor!

              Layouts will reparent its items to the layout's widget. This works at least if the layout is first created and assigned to a widget and then addWidget(...) is called. addWidget will reparent the widget. Not sure if this also works if you first add widgets to a layout and then assign the layout to a widget. If I write this kind of code by hand (instead of using the designer) I purposefully leave out the parent when I create widgets because it is not necessary (and more to type...).

              1 Reply Last reply
              0

              • Login

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