开发者

QMake: how to let UIC generate BOTH header and source files?

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().isEmpt开发者_运维技巧y())
            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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜