QMake:如何让UIC同时生成头文件和源文件?
在 .pro 文件中,我定义了 UI_HEADERS_DIR = ./uic/include UI_SOURCES_DIR = ./uic/src 但编译后,我只得到 ui_x.h 文件,其中包含声明和实现。
这是否意味着 QMake 无法生成仅包含最少声明的简单头文件并将所有实现细节放入源文件中?
这是生成的 .h 文件示例,您可以发现声明和实现都放置在 .h 文件中:
/********************************************************************************
** Form generated from reading UI file 'DemoDialog.ui'
**
** Created: Thu 21. Jul 16:08:58 2011
** by: Qt User Interface Compiler version 4.7.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
QT_BEGIN_NAMESPACE
class Ui_DemoDialog
{
public:
void setupUi(QDialog *DemoDialog)
{
if (DemoDialog->objectName().isEmpty())
DemoDialog->setObjectName(QString::fromUtf8("DemoDialog"));
DemoDialog->resize(400, 300);
retranslateUi(DemoDialog);
QMetaObject::connectSlotsByName(DemoDialog);
} // setupUi
void retranslateUi(QDialog *DemoDialog)
{
DemoDialog->setWindowTitle(QApplication::translate("DemoDialog", "Dialog", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class DemoDialog: public Ui_DemoDialog {};
} // namespace Ui
QT_END_NAMESPACE
in the .pro file, I defined both UI_HEADERS_DIR = ./uic/include UI_SOURCES_DIR = ./uic/src
but after compiling, I only get the ui_x.h files, which contain both declarations and implementations.
Is this mean QMake can't produce a simple header file containing only the minimal declarations and put all the implementation details into source file?
This is a sample generated .h file, you can find both declarations and implementations are placed within the .h file:
/********************************************************************************
** Form generated from reading UI file 'DemoDialog.ui'
**
** Created: Thu 21. Jul 16:08:58 2011
** by: Qt User Interface Compiler version 4.7.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
QT_BEGIN_NAMESPACE
class Ui_DemoDialog
{
public:
void setupUi(QDialog *DemoDialog)
{
if (DemoDialog->objectName().isEmpty())
DemoDialog->setObjectName(QString::fromUtf8("DemoDialog"));
DemoDialog->resize(400, 300);
retranslateUi(DemoDialog);
QMetaObject::connectSlotsByName(DemoDialog);
} // setupUi
void retranslateUi(QDialog *DemoDialog)
{
DemoDialog->setWindowTitle(QApplication::translate("DemoDialog", "Dialog", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class DemoDialog: public Ui_DemoDialog {};
} // namespace Ui
QT_END_NAMESPACE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
读取 .ui 文件并将其转换为代码的程序是“uic”,即用户界面编译器。
它不写出源文件:它只写标题。
请参阅其文档。
所以神秘的是为什么 qmake 变量引用page 费心说 UI_SOURCES_DIR 存在吗?
可能有一些未记录的 uic 选项现在或以前使 qmake 使 uic 写出 .cpp 文件。但即使有,我也不建议使用它,担心它将来会消失。
The program that reads a .ui file and converts it to code is 'uic', the User Interface Compiler.
It doesn't write out source files: it only writes headers.
See its documentation.
So the mystery is why the qmake variable reference page bothers to say that UI_SOURCES_DIR exists?
There may be some undocumented uic option that now, or previously, made qmake make uic write out a .cpp file. But even if there is, I would not recommend using it, for fear that it might disappear in future.