Qt6 migration - UIC generated code fails to compile (connect slots) - updated

537 views Asked by At

I'm trying to port my project from Qt5 to Qt6. My problem is that UIC generated code looks like this:

QObject::connect(SelectHome, &QToolButton::clicked, toQPSQLSettingUI, qOverload<>(&QWidget::selectHome));

MSVC2019 compilations fails with:

ui_toqpsqlsettingui.h(74,101): error C2039: 'selectHome': is not a member of 'QWidget'
C:\Qt\6.0.4\msvc2019_64\include\QtWidgets\qcompleter.h(57): message : see declaration of 'QWidget'
C:\Users\I542264\source\repos\tora\src\ui_toqpsqlsettingui.h(74,1): error C2065: 'selectHome': undeclared identifier

See the target is method is QWidget::selectHome, so IMHO MSVC is right: QWidget does not have method selectHome. But target should be sub-class method toQPSQLSettingUI::selectHome

Designer screenshot

Complete source is here. Initially created for Qt2, migrated to Qt3=>Qt4=>Q5.

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>toQPSQLSettingUI</class>
 <widget class="QWidget" name="toQPSQLSettingUI">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>600</width>
    <height>517</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="minimumSize">
   <size>
    <width>600</width>
    <height>0</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>Form1</string>
  </property>
  <layout class="QGridLayout">
   <property name="margin">
    <number>11</number>
   </property>
   <property name="spacing">
    <number>6</number>
   </property>
   <item row="0" column="1" colspan="2">
    <widget class="QLineEdit" name="PGSQL_HOME"/>
   </item>
   <item row="0" column="0">
    <widget class="QLabel" name="TextLabel6_2_2_2">
     <property name="toolTip">
      <string>The default dateformat to use when querying the database.</string>
     </property>
     <property name="text">
      <string>PgSQL home</string>
     </property>
     <property name="wordWrap">
      <bool>false</bool>
     </property>
     <property name="buddy">
      <cstring>PGSQL_HOME</cstring>
     </property>
    </widget>
   </item>
   <item row="1" column="0">
    <spacer name="verticalSpacer">
     <property name="orientation">
      <enum>Qt::Vertical</enum>
     </property>
     <property name="sizeHint" stdset="0">
      <size>
       <width>20</width>
       <height>40</height>
      </size>
     </property>
    </spacer>
   </item>
   <item row="0" column="3">
    <widget class="QToolButton" name="SelectHome">
     <property name="text">
      <string>...</string>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <tabstops>
  <tabstop>PGSQL_HOME</tabstop>
 </tabstops>
 <resources/>
 <connections>
  <connection>
   <sender>SelectHome</sender>
   <signal>clicked()</signal>
   <receiver>toQPSQLSettingUI</receiver>
   <slot>selectHome()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>606</x>
     <y>20</y>
    </hint>
    <hint type="destinationlabel">
     <x>314</x>
     <y>258</y>
    </hint>
   </hints>
  </connection>
 </connections>
 <slots>
  <signal>signal1()</signal>
 </slots>
</ui>
2

There are 2 answers

0
BillO On

The problem is that Qt6 UIC is using the new connect() syntax instead of the old SIGNAL()/SLOT() syntax, and it's scoping slots to the base class instead of the derived class. (In the OP's case, scoping selectHome() to QWidget instead of toQPSQLSettingUI.)

Adding the below to the .pro or .pri file and rerunning qmake causes UIC to use the old connect() syntax:

QMAKE_UIC_FLAGS += --connections string
0
fabiow On

steps to fix

  1. within qtcreator open the concerned UI file in designer
  2. press <F4> to toggle edit signals / slots
  3. double click the blue clicked() label to open the connection configurator
  4. click Edit... to customize the signals / slots
  5. add the missing slot selectHome()
  6. OK
  7. OK
  8. Save the UI file
  9. Compile

another way would be to edit the UI xml add within <ui><slots>

  <slot>selectHome()</slot>