I am building an application with mixed UI technologies (mostly C++ with some QML components included).
Suppose I have a QML item which I want to show inside a QDeclarativeView
using syntax like this:
view = new QDeclarativeView(QUrl::fromLocalFile("foobar.qml"));
I have added foobar.qml to my project in Qt Creator which automatically adds this line to the .pro file:
OTHER_FILES += \
foobar.qml
Now, you would expect including the file into the project to imply that it should be copied to the build folder, but it doesn't, and I get an error about missing foobar.qml in the build folder when I run the application. I'd hate to add custom build steps just to copy QML sources around, so is there some "de facto" way of doing this?
Creating and Running QML Projects For simple UI files such as this one, select File > New File or Project > Application (Qt Quick) > Qt Quick Application - Empty from within Qt Creator. Pressing the green Run button runs the application. You should see the text Hello, World! in the center of a red rectangle.
QML is a user interface specification and programming language. It allows developers and designers alike to create highly performant, fluidly animated and visually appealing applications.
Connecting to QML Signals All QML signals are automatically available to C++, and can be connected to using QObject::connect() like any ordinary Qt C++ signal. In return, any C++ signal can be received by a QML object using signal handlers.
If you want to have a Qt app that looks like an native OS app then you must go with QtWidgets. QML allows you to write a much more custom UI.
One obvious solution would be to include the QML source through Qt's resource system. This is hinted at on the doc page about deploying QML based applications.
EDIT: Here is the complete solution. I should learn to RTFM.
Do you use shadow builds? If so the application is build in a directory parallel to the source code. For testing you can change the working directory in Qt Creator (Projects in the left bar, then Execution of your build target). Using resources seems fool-proof, but it requires a rebuild every time any of the resources are changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With