简体   繁体   中英

Integrating ui.qml files into existing ui application

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM