Qt generate .ui file from old c++ project?
c++, qt
Solution
A well prepared project will isolate application logic from the UI layer, making it easier to make changes to or entirely replace the latter. If the project you want to convert is such, it should be doable to some extent.
if you keep the same naming, the most significant difference between your imperative UI and your `.ui` generated UI will be the extra `ui->` when you access UI members.
There is no tool to do all the work for you, but you could use `QObject::dumpObjectTree()` to get a tree-like representation of the UI, something like this:
QTabDialog::dialog <574,451,133,123>
QBoxLayout::unnamed
QBoxLayout::unnamed
QBoxLayout::unnamed
QPushButton::ok <45,91,82,26>
QTabWidget::tab widget <6,6,119,75>
QTabBar::tab control <0,0,48,24>
QToolButton::qt_right_btn I
QToolButton::qt_left_btn I
QAccel::tab accelerators
QWidget::tab base I
QWidgetStack::tab pages <0,22,119,51>
QFrame::first <2,2,115,47>
QObject::unnamed
QWidgetStackPrivate::Invisible::unnamed <2,2,115,47>
As you see, you can easily parse that and get the type and name of each object currently in the UI, you can use that information plus the meta system provided functionality to query properties and generate a XML .ui file.
Of course, you could have a more dynamic UI with elements dynamically created or removed, in which case it will be harder do to this. In that case you will have to do everything by hand.
Problem
I am new to Qt but have a good grasp of C++. I just learned qt design (QT5) to generate GUI and .ui file, and do coding in VS 2012. Now there is an old project which was written purely by hand, without the qt design. To maintain it, the code still needs to be written by hand. Is there any qt tool that can reverse-engineer the code to produce something that qt design can work on? So that any future GUI modifications can be don in qt design? many thanks