Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When and where the ui_XXX.h and ui_XXX.cpp are generated by uic tool?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    user001
    wrote on last edited by
    #1

    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?
    1 Reply Last reply
    0
    • A Offline
      A Offline
      Adrien Leravat
      wrote on last edited by
      #2

      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.

      Adeneo Embedded - www.adeneo-embedded.com

      1 Reply Last reply
      0
      • U Offline
        U Offline
        user001
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Adrien Leravat
          wrote on last edited by
          #4

          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.

          Adeneo Embedded - www.adeneo-embedded.com

          1 Reply Last reply
          0
          • U Offline
            U Offline
            user001
            wrote on last edited by
            #5

            Got it. Thanks.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved