4

So I have a simple app that uses QML for my graphical interface and c++ code for some of the logic. I was looking for a method to compile the QML into c++ code and link it into my binary and found this page over at the Qt home site:

http://doc.qt.io/QtQuickCompiler/

Basically it says use the resource system for all of my QML graphical interface files and add the QML compiler flag to my qmake config line in my .pro file and everything should be good to go.

As far as I know everything compiles fine, but when I use the the Qt windeployqt.exe tool to get all of the dependency files and test it on a clean system, I get a small white screen as if my QML files were not loaded properly.

I have one c++ reference to my main QML file using "qrc:/mainqml.qml" and that's it.

Any idea what I am doing wrong?

0

2 Answers 2

3

You're using the open source version of Qt. It didn't come with the Qt Quick compiler until Qt 5.11 where it is included - and after a rework, too. So it performs better than precompiled QML did in Qt 5.10 and before.

I get a small white screen as if my QML files were not loaded properly.

... thus you need to deploy these files with the application, otherwise it won't work.

add the QML compiler flag to my qmake config

That flag was a no-op on an open source Qt build until Qt 5.11.

Sign up to request clarification or add additional context in comments.

Comments

3

Qt Quick Compiler only shipped with Qt Commercial License, but you can still compile your QML files into qrc file. Starting a Qt Quick application project from Qt Creator does exactly this.

Deploying QML application with windeployqt require additional flag --qmldir, e.g.

windeployqt --(release or debug) --qmldir %PATH_TO_YOUR_QML_FILES% %YOUR_APPLICATION%.exe

It will parse your qml files and deploy all qml imports you used.

4 Comments

So if I understand properly, the Qt Quick Compiler just compiles .qml files, but by adding them to the .qrc resource file, they automatically get compiled into the final binary?
Both of them compile qml files into qt resource file (qrc) into final binary. Qt Quick Compiler, however, allows you to go a step further by compiling qml and javascript files into intermediate C++ code, therefore reduces the application startup time and allows for a much faster execution on platforms that do not permit Just-in-time compilation.
In your case, I suspect your deployment folder doesn't include necessary plugins and QML plugins. Using correct flag in windeployqt would fix this issue (since I have encountered such case myself).
Is this fix only for Windows?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.