summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2024-04-09 18:42:57 +0200
committerAxel Spoerl <axel.spoerl@qt.io>2024-04-12 12:32:16 +0000
commit2ec2c54e05656e04070ef1dc4b1e136a466c686c (patch)
tree8c2ea30887e9cc2da332ad548a98f58756ab4007 /tests/auto
parenta204417600c3cb84d287825afb0d433a8189f657 (diff)
uic: use qOverload for ambiguous slots
qOverload was used only for ambiguous signals and slots with no arguments. Connections to ambiguous slots made in widget designer's signal/slot editor, lead to an unresolved ambiguity when compiling the generated code in ui_xxx.h. One example is QLabel::setNum(), which can either take a double or an int. Always using qOverload is not an alternative, because signatures are normalised. E.g. const QString & / QString can't be distinguished. Add a map with all ambiguous signals and slots to customwidgetsinfo.cpp. Hardcode the map, because uic lives in QtCore and can't access meta objects of gui/widget classes. Use this map in isAmbiguousSignal() and add isAmbiguousSlot(). Change OverloadUse enum into an enum class in language.cpp. Change enum values to reflect the new condition for slots to use qOverload. Rename existing enum values and remove default argument in language::formatMemberFnPtr() to improve code readability. Apply const T& syntax for all types starting with Q, except QSize and QPoint. Revert 94c16517b3f8f01309a89598e698931ef77d60db, which was a hack forcing for QLCDNumber::display() to a string based connection. Add a new baseline to tst_uic, to test the above. Fixes: QTBUG-93413 Task-number: QTBUG-124241 Pick-to: 6.7 6.6 6.5 6.2 Change-Id: I49ccc1688cfc08970cce3e56adf18e5ac49a77e1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/tools/uic/baseline/qoverload.ui93
-rw-r--r--tests/auto/tools/uic/baseline/qoverload.ui.h98
2 files changed, 191 insertions, 0 deletions
diff --git a/tests/auto/tools/uic/baseline/qoverload.ui b/tests/auto/tools/uic/baseline/qoverload.ui
new file mode 100644
index 0000000000..fb9e5294b7
--- /dev/null
+++ b/tests/auto/tools/uic/baseline/qoverload.ui
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QSlider" name="horizontalSlider">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>TextLabel</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLCDNumber" name="lcdNumber"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>29</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>horizontalSlider</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>label</receiver>
+ <slot>setNum(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>199</x>
+ <y>67</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>199</x>
+ <y>172</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>label</sender>
+ <signal>linkActivated(QString)</signal>
+ <receiver>lcdNumber</receiver>
+ <slot>display(QString)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>199</x>
+ <y>126</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>199</x>
+ <y>218</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/tests/auto/tools/uic/baseline/qoverload.ui.h b/tests/auto/tools/uic/baseline/qoverload.ui.h
new file mode 100644
index 0000000000..4ab0e37d1f
--- /dev/null
+++ b/tests/auto/tools/uic/baseline/qoverload.ui.h
@@ -0,0 +1,98 @@
+/********************************************************************************
+** Form generated from reading UI file 'qoverload.ui'
+**
+** Created by: Qt User Interface Compiler version 6.8.0
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef QOVERLOAD_H
+#define QOVERLOAD_H
+
+#include <QtCore/QVariant>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QLCDNumber>
+#include <QtWidgets/QLabel>
+#include <QtWidgets/QMainWindow>
+#include <QtWidgets/QMenuBar>
+#include <QtWidgets/QSlider>
+#include <QtWidgets/QStatusBar>
+#include <QtWidgets/QToolBar>
+#include <QtWidgets/QVBoxLayout>
+#include <QtWidgets/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QWidget *centralWidget;
+ QVBoxLayout *verticalLayout;
+ QSlider *horizontalSlider;
+ QLabel *label;
+ QLCDNumber *lcdNumber;
+ QMenuBar *menuBar;
+ QToolBar *mainToolBar;
+ QStatusBar *statusBar;
+
+ void setupUi(QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName("MainWindow");
+ MainWindow->resize(400, 300);
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName("centralWidget");
+ verticalLayout = new QVBoxLayout(centralWidget);
+ verticalLayout->setSpacing(6);
+ verticalLayout->setContentsMargins(11, 11, 11, 11);
+ verticalLayout->setObjectName("verticalLayout");
+ horizontalSlider = new QSlider(centralWidget);
+ horizontalSlider->setObjectName("horizontalSlider");
+ horizontalSlider->setOrientation(Qt::Horizontal);
+
+ verticalLayout->addWidget(horizontalSlider);
+
+ label = new QLabel(centralWidget);
+ label->setObjectName("label");
+
+ verticalLayout->addWidget(label);
+
+ lcdNumber = new QLCDNumber(centralWidget);
+ lcdNumber->setObjectName("lcdNumber");
+
+ verticalLayout->addWidget(lcdNumber);
+
+ MainWindow->setCentralWidget(centralWidget);
+ menuBar = new QMenuBar(MainWindow);
+ menuBar->setObjectName("menuBar");
+ menuBar->setGeometry(QRect(0, 0, 400, 29));
+ MainWindow->setMenuBar(menuBar);
+ mainToolBar = new QToolBar(MainWindow);
+ mainToolBar->setObjectName("mainToolBar");
+ MainWindow->addToolBar(Qt::ToolBarArea::TopToolBarArea, mainToolBar);
+ statusBar = new QStatusBar(MainWindow);
+ statusBar->setObjectName("statusBar");
+ MainWindow->setStatusBar(statusBar);
+
+ retranslateUi(MainWindow);
+ QObject::connect(horizontalSlider, &QSlider::valueChanged, label, qOverload<int>(&QLabel::setNum));
+ QObject::connect(label, &QLabel::linkActivated, lcdNumber, qOverload<const QString&>(&QLCDNumber::display));
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
+ label->setText(QCoreApplication::translate("MainWindow", "TextLabel", nullptr));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // QOVERLOAD_H