How to use QML caching?



  • Hi; I have heard QML caching. I wonder, is this available on Qt Community Edition? I wrote these into .pro file:

    QT += quick
    CONFIG += c++11 qmlcache
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += main.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    TARGETPATH = MyCompany/Test
    QML_FILES = main.qml Page1.qml Page1Form.ui.qml qmldir
    load(qml_plugin)
    

    But I get this error:

    Project ERROR: Project has no top-level .qmake.conf file.
    Error while parsing file /home/username/QtApp/QtApp.pro. Giving up.
    Project ERROR: Must set TARGETPATH (QML import name)
    Error while parsing file /home/username/QtApp/QtApp.pro. Giving up.
    Project ERROR: Project has no top-level .qmake.conf file.
    Error while parsing file /home/username/QtApp/QtApp.pro. Giving up.
    Project ERROR: Project has no top-level .qmake.conf file.
    Error while parsing file /home/username/QtApp/QtApp.pro. Giving up.
    

    How can I use QML caching? Thanks.



  • You cannot load qml_plugin (nor qml_module) to an application project.

    http://doc.qt.io/qt-5/qtquick-deployment.html#limitations

    Currently this feature has some limitations:

    • Only QML and JavaScript documents that are part of a QML module can be compiled ahead of time.

    You need to split the components you want to be cached out of the main app to a separate QML plugin or module. If you create a QML plugin (QQmlExtensionPlugin), load qml_plugin. If you create a QML module without a C++ plugin (.qmldir + .qml/.js only), load qml_module.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.