Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the preferred way to include QML sources in your application build?

Tags:

build

qt4

qmake

qml

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?

like image 884
teukkam Avatar asked Oct 11 '10 10:10

teukkam


People also ask

How do I create a QML application?

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.

What is a QML application?

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.

How do you communicate between C++ and QML?

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.

Which one you would prefer for GUI development Qt widget or Qt QML?

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.


2 Answers

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.

like image 169
teukkam Avatar answered Oct 02 '22 13:10

teukkam


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.

like image 35
blakharaz Avatar answered Oct 02 '22 11:10

blakharaz