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

Koehne Kai Kai.Koehne at digia.com
Sat Dec 22 20:58:58 CET 2012


> Subject: [Interest] setMainQmlFile technique to avoid the need to copy QML      files
>
> 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 ad  > run it from there, or whether I have Qt Creator build my app in the default directory name it chooses for its buil 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 ../

Hi Steven,

good that it works for you, but it also has it's limitations: It will work e.g. not on Mac when you're creating an app bundle, or when developing for a device where an actual deployment step is involved. It will also not work if your shadow build directory is not exactly one level above.

Actually a somewhat more clean hack that you can use is to hardcode the absolute path. You can achieve this pretty e.g. adding to your .pro file:

DEFINES += QMLDIR=$$PWD/qml

and then use setMainQmlFile(QMLDIR/main.qml)

Anyhow, this doesn't work for deployment to a device either, for obvious reasons ...

Regards

Kai


More information about the Interest mailing list