Why does the ui_xxx.h include other custom-written header files?
-
Hi,
I was trying to understand a qt project developed by others. I am told that the ui_xxx.h is automatically converted from the .ui file with the help of qmake. But why I found two other custom-written header files are included in the ui-xxx.h? So what is that? I am a entry level learner. Any replies will be appreciated.
Regards
Xzhou
-
Hi and welcome to devnet,
Without more information, I would say that the others that have written the code did something wrong.
-
Well, the "UIC":http://qt-project.org/doc/qt-4.8/uic.html tool provided by Qt is used to generate header files (.h) from the ".ui" files. You are not supposed to edit those UIC-generated header files, because it will be overwritten the next time UIC is run. Anyway, we don't know whether your "ui-xxx.h" was really generated by UIC or is something else. If a file really was generated by UIC, its should start like this:
@** Form generated from reading UI file 'AboutDialog.ui'
**
** Created by: Qt User Interface Compiler version 4.8.6
**
** WARNING! All changes made in this file will be lost when recompiling UI file!@If your "ui-xxx.h" file indeed does start like this, then it should not contain any "custom" code and it should not include any "custom" header files. Still, somebody might have done something silly! Who knows ;-)
-
Or they "promoted":http://qt-project.org/doc/qt-5/designer-using-custom-widgets.html#promoting-widgets a generic widget to a custom widget.
In this case uic will include custom header files of the custom widgets in ui_xxxx.h file of the main widget.
-
Hi,
The ui_xxx.h file in my case starts with these:
@
/*******************************************************************************
** Form generated from reading UI file 'texo.ui'
**
** Created by: Qt User Interface Compiler version 4.8.5
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/#ifndef UI_TEXO_H
#define UI_TEXO_H#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QGridLayout>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QSlider>
#include <QtGui/QSpacerItem>
#include <QtGui/QStatusBar>
#include <QtGui/QTableWidget>
#include <QtGui/QToolBar>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#include "TexoView.h"
#include "TexoViewImg.h"
@The TexoView.h and TexoViewImg.h are two header files included in the ui_xxx.h file. And I can find the TexiView.h and TexoViewImg.h in the directory of the project file. So could you tell me why? I am sure the project works well.
Many thanks.
[quote author="MuldeR" date="1410390576"]Well, the "UIC":http://qt-project.org/doc/qt-4.8/uic.html tool provided by Qt is used to generate header files (.h) from the ".ui" files. You are not supposed to edit those UIC-generated header files, because it will be overwritten the next time UIC is run. Anyway, we don't know whether your "ui-xxx.h" was really generated by UIC or is something else. If a file really was generated by UIC, its should start like this:
@** Form generated from reading UI file 'AboutDialog.ui'
**
** Created by: Qt User Interface Compiler version 4.8.6
**
** WARNING! All changes made in this file will be lost when recompiling UI file!@If your "ui-xxx.h" file indeed does start like this, then it should not contain any "custom" code and it should not include any "custom" header files. Still, somebody might have done something silly! Who knows ;-)[/quote]
[andreyc EDIT]: Added @ around code.
-
Hi,
Can you tell me more details about this? Or can you give me some sources where I can look up? Thank you so much.
The ui_xxx.h file definitely is generated by .ui file. And the included custom-written header files can been found in the project.
[quote author="andreyc" date="1410390887"]Or they "promoted":http://qt-project.org/doc/qt-5/designer-using-custom-widgets.html#promoting-widgets a generic widget to a custom widget.
In this case uic will include custom header files of the custom widgets in ui_xxxx.h file of the main widget.[/quote]
-
Open texo.ui in a designer. Right click anywhere on a form.
Click on "Promoted widgets" in the context menu.
You should see a dialog with a list of promoted widgets.
It should include TexoView and TexoViewImg classes with their header files.If these lines do not exist then there is something wrong with the project.
-
They do exist in the list of promoted widgets. Thanks for this.
[quote author="andreyc" date="1410471126"]Open texo.ui in a designer. Right click anywhere on a form.
Click on "Promoted widgets" in the context menu.
You should see a dialog with a list of promoted widgets.
It should include TexoView and TexoViewImg classes with their header files.If these lines do not exists then there is something wrong with the project.[/quote]