Difference coding and using Qt Designer



  • Hi I am new on Qt and I don't understand the difference between :

    1. an application with windows, widgets and buttons coded "by hand" I mean create QFrame QLayout and arranging my widgets in them in the code then coding signal/slot etc ...
      OR
    2. the same application using QT Designer and placing my objects (layout frame whatever) graphically drag and dropping (with the designer) and doing signal/slot with the tool in designer and promoting my widgets in different classes.

    I see the difference in generating code with the "Ui::Dialog *ui;" object but I don't really understand what is it and I don't get the main thing of these two ways to code.
    Please could you tell me?


  • Moderators

    Hi! In the end both ways create the same result. If you write clean code by hand then you'll create a class for each of your windows and manually add the code to place the widgets in these windows where you want them. If your window is complex because it contains many widgets then this might become a bit hard because you have to keep a model of that window in your mind and imagine how things will look when you run them. Qt Designer helps you with that. Qt Designer is a graphical code editor and code generator: While you're using Qt Designer you can move around widgets in some kind of preview. During this time Qt Designer creates and manipulates a xml file (*.ui file) that stores all the information about what you want your window to look like, where all the widgets should be etc. When you're finished with designing your window you'll call qmake and this program will generate c++ code for you (a window class in a header and source file). This is just the same code that you could also have written by hand.



  • One of the things that I really love about Qt is the fact that the ui files are turned into good, clean C++.
    You can learn from reading the generated C++ files - I often do that.
    Most of the time, though, I write my code by hand, but - as Wieland says - Qt Designer is a Godsend for more complex interfaces. Or for things you don't want to spend time hand coding.. ;)



  • Hi, thank you for explaining it's very clear.

    So because I am struggling coding a simple application by hand I will probably try with the designer ^^
    Thank you


Log in to reply
 

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