Accessing the C++ code of objects created in Designer?

  • Is there a way to get access to all of the code that the designer (WYSIWYG layout editor) writes automatically? All I can see is the XML; I'm looking for stuff like where and how the objects are initialized, etc. I assume (could be wrong) that all of this stuff is going on under the hood somewhere. As a Qt beginner it's great to have it do so much for me, but there are many things it does I'd like to see exactly how it's doing them, be able to do tweak myself in code, etc. Is this possible, or does creating stuff in the designer mean certain code is unavoidably hidden?

  • Moderators

    When you run qmake, it automatically invokes uic (ui-compiler). What it does is, it takes .ui XML files and generates a header file "ui_<filename>.h" that is then used in your code. You can take a look into that file any time you like, just remember it will be regenerated automatically, so changing it by hand is a bad idea. As to where this file/ files are being stored, it depends on the .pro file, but typically they will sit together with remaining build objects (.o etc).

  • Hmm, I see, so they're quite different. That's kind of unfortunate :( thanks though.

  • If you want more control over how the UI elements are created you could just create them directly in your code; you don't have to use the designer.

    If you don't already have it, the book 'C++ GUI Programming with Qt4' covers this approach in some detail. More information here:

Log in to reply

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