How to create .ui file for manually edited application (.h & .cpp only)?

  • I have Qt 5.5 Creator and Qt 5.5 Designer working in Ubuntu 14.04.
    I have walked through creation of several example projects which generate *.ui file per project allowing Qt objects to be edited in Qt Creator.

    Next I explored a manually coded test application here ...

    This uses .h and .cpp and image files manually edited and placed in project folder.



    But there is no *.ui file in the project since this was not created through Qt Creator.
    I can open this C++ project in QtCreator and Run to see the working app.

    My first question is ..

    Q. How can I create a *.ui file from a manually edited app (as above) so that it can be edited in Qt Creator and extended?

    While there is a process for .h and .cpp to create .ui, it seems that there is no tool I've found to reverse engineer this process. Although I read through here ..

    ... ...

    I thought to get around this I might be able to create a blank widget container in Qt Creator and import the above test C++ app. But I don't see how to do this in Qt Creator .. integrating external coded apps.

    My second question is ..

    Q. How do I integrate external .h and .cpp files (external app) into a Qt Creator created project?

    I found this discussion.

  • Moderators

    How can I create a *.ui file from a manually edited app

    • In Qt Creator go to File -> New File or Project -> Qt -> Qt Designer Form. Select a widget type, e.g. Widget and give the file a meaningful name (usually the same as your h/cpp file): mainwindow.ui. It will be added to you project.
    • Open it in the designer, select the widget and set its property objectName to match the name of your class in your h/cpp (it's not necessary but recommended to keep things in order).
    • In your .h file add:
    namespace Ui {
    class MainWindow; //this is the property `objectName` from the previous step. They need to match

    and then a private field in your class declaration:

    class MainWindow : 
       Ui::MainWindow* ui; //this is again the matching name
    • in your .cpp file include the header generated by uic: #include "ui_mainwindow.h". the mainwindow part is the name of your .ui file.
    • in your constructor create the ui instance and setup:
    MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
    • in the destructor destroy the ui instance:
    MainWindow::~MainWindow() {
       delete ui;

    How do I integrate external .h and .cpp files (external app)

    just open your .pro file and add them to HEADERS and SOURCES variables.

Log in to reply

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