Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to create .ui file for manually edited application (.h & .cpp only)?

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

Scheduled Pinned Locked Moved Qt Creator and other tools
2 Posts 2 Posters 15.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eureka
    wrote on 9 Feb 2016, 14:21 last edited by
    #1

    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 ...

    http://doc.qt.io/qt-5/qtwidgets-mainwindows-application-example.html

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

    Files:
    mainwindow.cpp
    mainwindow.h
    main.cpp
    application.pro
    application.qrc

    Images:
    images/copy.png
    images/cut.png
    images/new.png
    images/open.png
    images/paste.png
    images/save.png

    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 ..

    http://stackoverflow.com/questions/16004235/qt-generate-ui-file-from-old-c-project

    ... ...

    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.

    http://www.qtcentre.org/threads/56441-How-to-use-external-source-code-in-Qt-creator/page2

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 9 Feb 2016, 15:03 last edited by Chris Kawa 2 Sept 2016, 15:03
      #2

      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 : 
      ...
      private:
         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) {
         ui->setupUi(this);
      }
      
      • 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.

      1 Reply Last reply
      0

      1/2

      9 Feb 2016, 14:21

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved