1

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>
Yun
  • 3,056
  • 6
  • 9
  • 28
ibre5041
  • 4,903
  • 1
  • 20
  • 35
  • 1
    This line: `` tells that the class of `toQPSQLSettingUI` is `QWidget`. But in order to use the `selectHome` slot (which does exists in a subclass, I assume), you need to "promote" the widget to the subclass (which is done by right-clicking the widget in Qt Creator design mode and then choosing the promote action). – cbjeukendrup May 21 '21 at 22:14
  • Did you ever find a solution to this? I have too many .ui files to edit them with Qt Designer or even manually. – keith969 Dec 10 '21 at 10:27
  • I have not. I just had to stop using QDesigner to connect slots. And I rewrote mine code to use connect on source code level. Luckily then new connect mechanism based on templates, simply won't compile if you make a typo. – ibre5041 Dec 10 '21 at 12:03
  • See here https://github.com/tora-tool/tora/commits/qt6 , https://github.com/tora-tool/tora/commit/c8e215e33f3ce6ccc7b2cc71c67fcc5914bf5940 – ibre5041 Dec 10 '21 at 12:21

2 Answers2

1

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>
fabiow
  • 11
  • 2
1

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
BillO
  • 11
  • 1