UIC doesn’t use the object name to create UI_MyClass.h
-
Hi all,
I am using QtCreator 12.0.1 with Qt kit 4.8.7 (32 bit) on Linux 64 bit.
I am seeing some strange behaviour on UI files, in UI_MyClass .h the pointers to objects don’t use the objectName to naming the variables.So, if I have a pushButton named “pushButtonMy” (see formtest.ui), in UI_MyClass.h I see a pointer named “pushButton” (see ui_formtest.h) and I don’t know why.
In formtest.ui
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>FormTest</class> <widget class="QWidget" name="FormTest"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <widget class="QPushButton" name="pushButtonMy"> <property name="geometry"> <rect> <x>10</x> <y>10</y> <width>92</width> <height>30</height> </rect> </property> <property name="text"> <string>PushButton</string> </property> </widget> </widget> <resources/> <connections/> </ui>
in ui_formtest.h
/******************************************************************************** ** Form generated from reading UI file 'formtest.ui' ** ** Created by: Qt User Interface Compiler version 4.8.7 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_FORMTEST_H #define UI_FORMTEST_H #include <QtCore/QVariant> #include <QtGui/QAction> #include <QtGui/QApplication> #include <QtGui/QButtonGroup> #include <QtGui/QHeaderView> #include <QtGui/QPushButton> #include <QtGui/QWidget> QT_BEGIN_NAMESPACE class Ui_FormTest { public: QPushButton *pushButton; void setupUi(QWidget *widget) { if (widget->objectName().isEmpty()) widget->setObjectName(QString::fromUtf8("widget")); widget->resize(400, 300); pushButton = new QPushButton(widget); pushButton->setObjectName(QString::fromUtf8("pushButton")); pushButton->setGeometry(QRect(10, 10, 92, 30)); retranslateUi(widget); QMetaObject::connectSlotsByName(widget); } // setupUi void retranslateUi(QWidget *widget) { widget->setWindowTitle(QApplication::translate("FormTest", "Form", 0, QApplication::UnicodeUTF8)); pushButton->setText(QApplication::translate("FormTest", "PushButton", 0, QApplication::UnicodeUTF8)); } // retranslateUi }; namespace Ui { class FormTest: public Ui_FormTest {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_FORMTEST_H
thanks in advance
CP71 -
If you want a ui file which works with uic from Qt4 you must use a designer from Qt4 and not one from Qt5 or Qt6 as they produce a xml file which can not be properly parsed with the ancient Qt4 uic. I already told you this in my first post here.
-
I would guess the ui is created with Qt6 designer (inside QtCreator) but uic from Qt4 can't handle this anymore. Create your ui with Qt4 designer and see if the objectName is correctly created.
-
@Christian-Ehrlicher
Hi,
Thank you so much for your response.
Yes, I created the user interface in my post using QtCreator 12.0.1 and processed it with UIC 4.8.7.But I have encountered this issue on UIs created with Qt 3.2.1 and normally processed by UIC 4.8.7.
I created the same simple widget in both QtCreator and compared them and they are identical .
-
@CP71 Then uic from Qt4 can't handle object names or has a bug.
But I think you did something wrong in your test. A ui file from Qt3 sets the name of an object as <property name="name" >... Don't know what Qt4 does though. -
Then uic from Qt4 can't handle object names or has a bug.
Yeah, at least it looks that way.
I will try to investigate, if I find the way, I will update you.Now I have only one idea:
I cross compiled the Qt 4.8.7 x86 on my Linux 64 bit, maybe something went wrong, is it possible?
But I sound it very strangeBut I think you did something wrong in your test. A ui file from Qt3 sets the name of an object as <property name="name" >... Don't know what Qt4 does though.
I think you are right, but I don’t know what is wrong.
Below you can see the UI created by QtCreator 3.2.1 and normally processed in my VM with Linux 32 and Qt 4.8.7 32 bit.
But not processed in my Linux 64 bit with Qt 4.8.7 32 bit.<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Form</class> <widget class="QWidget" name="Form"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>200</width> <height>200</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <widget class="QPushButton" name="pushButtonMy"> <property name="geometry"> <rect> <x>30</x> <y>20</y> <width>100</width> <height>30</height> </rect> </property> <property name="text"> <string>PushButton</string> </property> </widget> </widget> <resources/> <connections/> </ui>
@Christian-Ehrlicher Thank you very much for your time!
-
Are you sure your QtCreator 3.2.1 is built with Qt4?
-
@Christian-Ehrlicher
Yes, I confirm.
In my VM I have QtCreator 3.2.1 (Based 5.3.2 GCC 4.9.2) with Qt 4.8.7 32 bit.It works well, I didn't see issues.
Only for curiosity, do you see something of strange in this configuration?
-
@CP71 You show clearly that QtCreator is built with Qt5. Create your ui files with a Qt4 based designer.
-
@Christian-Ehrlicher
Excuse my English :(, but I believe I didn't understand the purpose of this sentence..
Do you think this configuration is a problem? -
If you want a ui file which works with uic from Qt4 you must use a designer from Qt4 and not one from Qt5 or Qt6 as they produce a xml file which can not be properly parsed with the ancient Qt4 uic. I already told you this in my first post here.
-
@Christian-Ehrlicher
I understand, but then I don't understand how I didn't notice UI issues until now.If I understand correctly, I am using a Qt5 design (QtCreator) with incompatible UIC (Qt4) without ever encountering any issues, how is that possible?
"Anyway, thanks for the info, I'll proceed to downgrade QtCreator based on Qt4
-
There is no need to downgrade QtCreator. Just edit your ui files with the correct designer executable instead inside QtCreator.
-
@Christian-Ehrlicher
Thank you, I like it better this way. ;)Just out of curiosity, do you have any idea why I've never seen any UI issues in the VM?
-