deploy resulable QML files
Hello,
I have finally arrived at creating a few QML files that provide generic items that I would like to reuse in multiple projects. Ideally, I would like to be able to use these files at development time such that they are recognized in QtCreator, and at runtime. After some time of investigation, I have come to understand that there must be a qmldir file somewhere which points to the QML files.
Heres my questions:
- how would QtCreator know at development time where to find the qmldir file?
- how would my application at runtime find the file?
- is there any way to handle reusable QML witout copying around files?
as far as 1 and 2 goes, my current assumption is that I would have to set the QML_IMPORT_PATH environment variable and copy the files to that location (DONT like that). As far as 3. goes, I have tried to run the command
Code:
rcc -binary mycontrols.qrc -o mycontrols.rcc
to create a binary resource, which I then added to my application via
Code:
QResource::registerResource("mycontrols.rcc", p
);
That obviously didn't work in the IDE, and yielded a "qrc:NavigationPanel": no such directory at runtime from the QML file referenceing the component. So what options do I have?
thanks,
Christian
Re: deploy resulable QML files
ok, I am answering myself. I was able to build a C++ plugin module which contains the QML files as resources and publishes them via
Code:
const QUrl tileUrl
("qrc:NavigationTile.qml");
qmlRegisterType(tileUrl, uri, 1, 0, "NavigationTile");
const QUrl panelUrl
("qrc:NavigationPanel.qml");
qmlRegisterType(panelUrl, uri, 1, 0, "NavigationPanel");
unfortunately, I also had to register helper QML files which I did not want to publish, but otherwise the above files would not execute. Now, If I could also do away with the qmldir file, I would have a neat and compact module publishing mechanism.
Re: deploy resulable QML files
QML has a similar concept to libraries or plugins in C++, calles modules http://qt-project.org/doc/qt-5/qtqml-modules-topic.html
Qt's own QML support, e.g. QtQml, QtQuick, QtQuick.Controls and so on are done that way.
Cheers,
_
Re: deploy resulable QML files
Quote:
Originally Posted by
anda_skoa
been there, read that. However, the documentation only mentions plugins as a way to implement complex backend logic and integrate it with QML. What I am talking about here is publishing plain QML types, which consist only of QML files kept as resources inside a shared library. The only C++ code involved is the Plugin::registerTypes(const char *uri) implementation
Quote:
Qt's own QML support, e.g. QtQml, QtQuick, QtQuick.Controls and so on are done that way.
not true. If you look, theres several dozen .qml files beneath the qml directory in your Qt install path. These files are imported directly from the filesystem by a QtQuick application at runtime.
Re: deploy resulable QML files
Quote:
Originally Posted by
doulos
been there, read that. However, the documentation only mentions plugins as a way to implement complex backend logic and integrate it with QML.
Yes, that's one the things a module can do-
Quote:
Originally Posted by
doulos
not true. If you look, theres several dozen .qml files beneath the qml directory in your Qt install path. These files are imported directly from the filesystem by a QtQuick application at runtime.
A module doesn't have to be a single file. It can be implemented as just a shared library (e.g. QtQml.Models), a directory with QML files, a combination of both (e.g. QtQuick.Controls)
Cheers,
_
Re: deploy resulable QML files
Quote:
A module doesn't have to be a single file. It can be implemented as just a shared library
if you read my second post, I was talking about a QML plugin (shared library) specifically. So lets keep the term module aside and focus on that. My "achievement" was to maintain QML files within a plugin and publish them from there, which allows me to deploy just on file (2, actually, because of that nasty qmldir file)
Re: deploy resulable QML files
Below is an "official" statement (from here) that describes why deploying reusable QML in the form of a compiled plugin makes a lot of sense. Now, what I would really love to see is the removal of the qmldir file (the only remaining non-compiled filesystem artifact). Why not let the shared lib provide ALL the meta information - which would basically only require adding a "registerNamespace" function.
Quote:
Compiled Qt Quick
With Qt 5.3 we are introducing a first look at a new professional build tool available under the Qt Enterprise version, Qt Quick Compiler. The compiler takes QML files and compiles them to native code showing a big difference in performance on operating systems where one cannot use a Just in time compiler, namely iOS and WinRT.
The compiler is also very useful to improve load times of QML user interfaces, as all of the parsing work now happens at compile time. This is especially interesting for startup times of applications and boot times of devices using Qt Quick for the user interface.
Finally, the compiler helps keep your source code safe, as it is now no longer necessary to ship the sources of your QML-based application.
Check out the documentation for more details.
Re: deploy resulable QML files
You could likely provide a patch that uses Q_PLUGIN_METADATA or a similar mechanism to store the qmldir inside the binary and have the plugin loader look for it there as well.
Cheers,
_