[Interest] setMainQmlFile technique to avoid the need to copy QML files

VStevenP vstevenpavao at yahoo.com
Sat Dec 22 05:07:25 CET 2012


I just discovered a pretty simple and convenient technique that allows my compiled-and-linked Qt .pro app to easily resolve to one-and-only-one main QML file, whether I build my app from the command line in my app dir and run it from there, or whether I have Qt Creator build my app in the default directory name it chooses for its build and let Qt Creator run it from there.

Basically, I prefix the relative path to the main QML file with the name of the my app root directory, preceded by ../


For example, say my app is called test.  I have a "test" directory that contains test.pro, and main.cpp.  Let's say the main QML file is test/qml/test.qml

The following relative path will allow the app to resolve to the one-and-only-one main QML file (test.qml), whether or not I build and run the app on the command line in the directory "test", or whether Qt Creator builds and runs it in a sister directory called test-build-Desktop_Qt_5_0_0_GCC_32bit_SDK-Debug   (This is the default Debug build path Qt Creator chose by default for my system, which I accepted when I configured the project in QtCreator.)

viewer.setMainQmlFile(QStringLiteral("../test/qml/myapp.qml"));

With this technique, it seems there's no need to copy QML around to do some simple debugging in QtCreator, or to involve the Qt resource system, just so apps built in either of those 2 directories can find the one master copy of test.qml.

Is anyone else using this technique, or does anyone have some other simple techniques they're using (perhaps some QT environment variable) to avoid copying QML from one place to another in order to easily debug in Qt Creator.




More information about the Interest mailing list