Search code examples
c++pythonqtuser-interfaceqt-designer

Qt Designer generate C++ code


Is it possible to see C++ code with Qt Designer ? I can draw my interface and have it saved as a .ui file. Also, I can generate python code from .ui file using a .bat file. But I cannot view C++/Qt code generated from the UI, which I would like to get.

I looked for it and all I can find is doc. about how to generate the python from the .ui, which I can do but is not what I am looking for.

Thanks


Solution

  • The menu item "Form/View Code" is exactly what you expect - it shows the generated C++ code:

    Screenshot from Qt designer

    As you can see from the comments in the generated file, Qt designer also uses uic (the Qt User Interface Compiler) to generate the code preview.

    You can verify if uic works properly by manually creating the source code:

    • save your form to a .ui file, e.g. sample.ui
    • Run uic -o sample.h sample.ui from a command shell
    • sample.h then contains the generated source code