Qt compilation process



  • Hi Everyone,

    I want to know about compilation process involved in Qt projects. I am from Embedded C Background,I know about how compilation how c & c++ projects are compiled and executable is getting generated .Is there any detailed documentation available for Qt.Thanks in advance, Have a nice day.


  • Moderators

    That is a very general request, so I won't get into too many details. In essence, most Qt projects (based on qmake, qbs or cmake) are doing this:

    • generate meta object information using moc
    • generate resources using rcc
    • generate UI files using uic
    • compile all those files and the source code using the specified compiler
    • link and produce the shiny, new binary :)


  • Hi,

    Thanks for pointing out essence of Qt compilation . I like to understand few more questions

    i) what is Qobject ?F
    From documentation I came to know that standard c++ objects are static , Q object provides dynamic objects which is processed by moc and then it will be compiled and linked .correct me if i am wrong

    ii) how .ui( form files) are linked with c++ code. will .ui files will be converted to c++ before compiling.

    iii) is there any simple block diagram describing entire compilation process(like how qt c++ extensions are converted into meta code and then linked to c++ compiler and how single executable is generated )


  • Moderators

    I recommend creating a simple test app and investigating the generated files.

    Here are the answers:

    In general, there are 2 planes on which you can consider what a QObject is. Basically, it's a C++ class like any other: you can do the same things with it (apart from object copying and inheriting from it twice). On another, by means of Meta Object Compiler (moc) and Qt Meta Object System, QObjects acquire some special properties: they can use Qt's signals and slots, be created and manipulated by QMeta* classes, you can search through the parent-child hierarchy, and many more. All this is in Qt documentation, just search for the phrases I've put in bold. MOC generates QObject meta information as a standard C++ source file, you can easily look it up after you build your project

    uic (UI compiler) generates a standard C++ header file with all the UI information, this is then linked into your application just like any other header

    No, because the process does not modify the C++ standard in any way. All Qt tools (uic, rcc, moc) are code generators, the files that they create are valid C++ code. This also ensures high performance of the whole system - there is no runtime parsing of any information



  • read the qt's doc on what do the moc and uic are doing, it's very clear :)

    bq. From documentation I came to know that standard c++ objects are static

    to be honest this is wrong, in c++ objects could be created either static, at compilation time, or dynamic at run time ... on the other hand the c++ compilers have a static type checking mechanism and moc and uic rely on it to generate code then safely linked to the implementation of QObject's class



  • Hi sierdzio,

    I have compiled small Qt project and i have understood how ui and qobjects are treated. I have one more doubt, i have created qt gui project named gui_demo
    which automatically creates
    i)gui_demo.h
    ii)main.cpp
    iii)gui_demo.cpp

    in main.cpp
    we create object for gui_demo which inherits Qmainwindow calls when i create object i understood , it will initalize base class constructor QmainWindow.i didnt understood ui(new UI::gui_demo) which is also in the part of base class constructor. is ui(new UI::gui_demo) is a base class,why we assiging gui_class object to it and what will setupUI member will do?
    gui_demo::gui_demo(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::gui_demo)
    {
    ui->setupUi(this);
    }

    Regards,
    tamil


  • Moderators

    Please wrap any code you post to this forum between '@' tags, it makes it much easier to read.

    OK, now we are entering some delicate territory ;) By that I mean that I'll be saying some things from memory and I might be not entirely right.

    When you create a new project, Qt Creator generates some code for you, and one of the things it does it to wrap your GUI header in a UI namespace:
    @
    namespace UI {
    class gui_demo;
    }
    @

    This is not really required by Qt, just a convention that Qt Creator prefers. It also adds a private UI member to your class:
    @
    private:
    Ui::gui_demo *ui;
    @

    Again, this is not required, and same effect can be achieved in other ways. You can ignore that for now. The part you asked about, ui(new UI::gui_demo) is not about initializing a base class, it's just a simple variable assignment done in constructor initialisation list (standard C++ code again :)). The variable holds the code generated by uic in ui_gui_demo.h file. You can look up what setupUi() does right there. The method basically creates all GUI objects for you, places them inside all the layouts specified in the UI file, and then assigns "this" as the parent window for that whole user interface. So it needs the pointer to your QMainWindow only to know who is "the boss".

    Hope that's clearer now. Don't hesitate to ask for more info :)



  • Hi sierdzio,

    Thanks for your valuable time.I have one more doubt :) .The uic compiler will generate ui_projectname header file with ui_projectname as well as class(in my case ui_mainwindow) right .In ui_mainwindowheader. The derived class(mainwindow) inheriting the class ui_mainwindow in public scope.

    snippet:(ui_mainwindow.h)
    i)
    @namespace Ui {
    class MainWindow: public Ui_MainWindow {};
    } // namespace Ui
    @

    ii) also what mean by QT_QT_BEGIN_NAMESPACE, QT_END_NAMESPACE

    My doubt is,In our derived class constructor(main window) why we have not initialized the the constructor of ui_mainwindow,(which is also a base class for mainwindow) .?
    snippet :(mainwindow.cpp)
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    @


  • Moderators

    Maybe your implementation is different (it can be), but usually the main window does not inherit from the UI class... it only includes an object of that class as a private member.

    QT_BEGIN_NAMESPACE is pretty much Qt-internal. It can be used when you want to compile Qt inside a namespace, AFAIK.



  • I didn't understand properly, could you please explain with some example if possible.Thanks in advance.


  • Moderators

    Hi,

    There are different ways for Qt Designer to generate C++ code, all described at http://qt-project.org/doc/qt-5.1/qtdesigner/designer-using-a-ui-file.html

    Sierdzio's example used the "member variable" approach, while tamilhce's example used the "inheritance" approach. Both are valid. You can choose your preferred approach in Qt Creator's settings: Tools -> Options -> Designer -> Class Generation -> Embedding of the UI Class

    QT_BEGIN_NAMESPACE and QT_END_NAMESPACE are not meant to be used by developers. You can pretend that they don't exist. ;)



  • Hi Everyone,

    Thanks for your information, Now i understand how ti actually works.

    Regards,

    Tamil



  • Hi
    I want to develop a simple windows desktop application,which will has to capture bio-metric sensor connected to the pc in windows platform . The bio-metric vendor has provided api() in Acticex, .Net & java to which i can connect to bio-metric sensor to capture , store,show&compare bio-metric images etc.My questions are :

    i) how can I integrate the given api() in my Qt appication (in windows) to capture and display the bio-metric image

    ii) which of the package is easy to integrate with Qt (for windows desktop application) i) Active X ii) .Net iii)Java
    iii) if possible give me simple example to integrate third party api() with Qt ,which can be helpful for my development.I have made this as separate post but didn't get any reply

    Thanks in Advance,
    Regards,
    Tamil


  • Moderators

    Hi,

    Please wait at least 2 days before re-posting. SGaist replied to your other post within 10 hours, which is very fast already (remember that some people might be asleep or busy when you post). Give his advice a try, and post any follow-up questions in the other thread.

    Good luck.



  • HI

    I am successfully integrated bio metric device with Qt through Activex, The Qt help documentation is really awesome.Thanks for your valuable reply .special thanks to sierdzio, who helps me to understand the fundamentals in a better way .

    Regards,
    Tamil


  • Moderators

    I'm happy to hear that. Have fun with Qt, like we all do :)



  • Hi sierdzio,

    I using Qt gui , and yet to try Qt Quick, which one will give good flexibility.


  • Moderators

    Both. They have different target markets, so to speak. Once you learn how Qt works and are quite happy with QtWidgets, do try QtQuick. When you know both decently well, you will also be able to decide which one to choose :)

    Sorry I won't give you any more definite answer here. I really think both technologies are good and very useful, but for different use cases.


Log in to reply
 

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