When and where the ui_XXX.h and ui_XXX.cpp are generated by uic tool?



  • I am going through examples of C++ GUI Programming with Qt 4 books. I am using Qt 5.0.2. In the GoToCellDialog example, I run qmake from Qt creator but cannot find any header file or C++ files are generated.

    When I created the project. Qt Creator create a main.cpp for me and its fine to run with it without any generated .h and .cpp files:

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    GoToCellDialog w;
    w.show();

    return a.exec();
    

    }@

    The book gave the following main which require the generated .h and .cpp file I think. So I got compile errors.

    @int main(int argc, char *argv[])
    {
    Ui::GoToCellDialog ui;
    QDialog *dialog = new QDialog;
    ui.setupUi(dialog);
    dialog->show();

    return a.exec();
    

    }@

    My questions are:

    1. how to use uic tool to generate .h and .cpp files from Qt Creator? I do need them.
    2. which main method I should use?


  • Hi,

    1. When creating a gui class through QtCreator, it is automatically added to the forms of the project. If you created the ui manually, you have to add it to your project .pro file.

    @FORMS += myform.ui@

    uic then compile the ui (xml) file into valid C++ that can be included.

    1. In real application, in most situation, you create a Gui Class, that holds its own Ui (and ui pointer). So you'd use the first "main". In addition it's way safer and easier to use.


  • [quote author="Adrien Leravat" date="1373553846"]Hi,

    1. When creating a gui class through QtCreator, it is automatically added to the forms of the project. If you created the ui manually, you have to add it to your project .pro file.

    @FORMS += myform.ui@

    uic then compile the ui (xml) file into valid C++ that can be included.
    [/quote]

    I create the Form project via Qt 5.0.2 Creator. The .pro file is created by Creator contains the FORMS += gotocelldialog.ui:

    @QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = Test4
    TEMPLATE = app

    SOURCES += main.cpp
    gotocelldialog.cpp

    HEADERS += gotocelldialog.h

    FORMS += gotocelldialog.ui@

    When I run qmake from Creator, there is no ui_gotocelldialog.h and ui_gotocelldialog.cpp file generated. So I am confused because the doc says: If you use qmake, uic will be invoked automatically for header files.

    It seems the uic is not invoked by the qmake from Creator.



  • Yes I confirm, doing a simple "qmake" do not generate the Ui header file.
    When compiling, uic is invoked.

    @C:\Qt\Qt5.0.2\5.0.2\mingw47_32\bin\uic.exe ..\untitled1\mainwindow.ui -o ui_mainwindow.h@

    This is probably a change that came with QtCreator. But nothing you'd worry about. The important point in your book, I guess, is understanding that there is qmake, which processes Qt macros from your .h/.cpp files, uic, which compiles uis, another for qrc resource files, etc.

    Also note that there is no cpp ui at all, everything is contained in the .h.



  • Got it. Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.