Important: Please read the Qt Code of Conduct -

My first Qt widgets app

  • Hello, so I have a bit of experience with Qt but very little (never used the designer). I just recently started a hello world widgets app and after double clicking the mainwindow.ui file it brought up the designer. I was able to drag and drop a label and everything worked fine. However, when I went to browse the code for that label, I was supersized when I did not find it in main.cpp. In fact, I can't seem to find it anywhere. Apparently creating a label with the designer is not the same thing as creating a label like this:

    QLabel label;

    I figured the designer was auto generating code, where is that code? Please help me understand what it is exactly that I do not understand XD

  • Lifetime Qt Champion

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Designer generates a .ui file which contains an XML description of your widget.

    The you have the uic tool that is going to generate the code needs for your widget to be setup. You'll end up with 3 files:

    • The .uic that you keep in your sources
    • The code generate from the .uic file that you don't keep in your sources
    • The code of the widget that will use what was generated plus what you write in it for the logic. File that you keep.

    For more information see the Qt Creator documentation about the widget designer and the designer documentation itself.

  • @SGaist Awesome, thanks, I missed the text for the label because I figured it would be created in the main.cpp and surrounded with double quotes but I found it in the .ui file:

    <string>This is the label text</string>

    So would you suggest using designer for a larger application? Are there limitations to the designer that I should be aware of? I will go through the documentation but what do you think, in general, about the designer?

  • Lifetime Qt Champion

    It frankly depends on your taste.

    I personally always code everything by hand but it's a matter of habit. Do what you find best for your development process.

Log in to reply