Integrating ui.qml files into existing ui application

Viewed 40

I've created a small application. The GUI is ugly, I've done it quickly. I've created a ui.qml file with Qt Design Studio.

My question is : is it simple to use my ui.qml file instead of my ui file ? I mean, do I have to change all my code when I call ui->ComponentName ?

I tried to understand how ui.qml files works, but it seems it's a completely different way to use component in C++ files than ui files..

1 Answers

Depending on the build system you are using, files ending with .ui are used by autouic to generate C++ code that you can call to create your user interface, usually from the constructor of your class that will be the parent for those components.

This is done by calling setupUi on the member variable 'ui', which is the same class name as the parent class, just under the Ui namespace.

QML code is interpreted, however, and can be read by QQmlApplicationEngine. You can expose properties with setContextProperty, taking a QString and a QObject*, as explained further here: https://doc.qt.io/qt-6/qtqml-cppintegration-exposecppattributes.html#exposing-methods-including-qt-slots

Related