Results 1 to 8 of 8

Thread: deploy resulable QML files

  1. #1
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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:
    1. how would QtCreator know at development time where to find the qmldir file?
    2. how would my application at runtime find the file?
    3. 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
    Qt Code:
    1. rcc -binary mycontrols.qrc -o mycontrols.rcc
    To copy to clipboard, switch view to plain text mode 
    to create a binary resource, which I then added to my application via
    Qt Code:
    1. QResource::registerResource("mycontrols.rcc", p);
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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
    Qt Code:
    1. const QUrl tileUrl("qrc:NavigationTile.qml");
    2. qmlRegisterType(tileUrl, uri, 1, 0, "NavigationTile");
    3.  
    4. const QUrl panelUrl("qrc:NavigationPanel.qml");
    5. qmlRegisterType(panelUrl, uri, 1, 0, "NavigationPanel");
    To copy to clipboard, switch view to plain text mode 
    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  4. #4
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: deploy resulable QML files

    Quote Originally Posted by anda_skoa View Post
    QML has a similar concept to libraries or plugins in C++, calles modules http://qt-project.org/doc/qt-5/qtqml-modules-topic.html
    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
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: deploy resulable QML files

    Quote Originally Posted by doulos View Post
    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 View Post
    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,
    _

  6. #6
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: deploy resulable QML files

    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)

  7. #7
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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.

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. Replies: 5
    Last Post: 30th October 2012, 08:52
  2. Replies: 1
    Last Post: 15th August 2011, 23:26
  3. Replies: 12
    Last Post: 17th June 2009, 05:34
  4. visual studio project files - adding extra files
    By luf in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 21:05
  5. how to save sequences of text files and sound files
    By nagpalma in forum Qt Programming
    Replies: 8
    Last Post: 3rd July 2007, 00:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.