Is there any way how to implement dynamical file-resolver for missing Qml components in QmlEngine? How to implement dynamically loading of external resources to QmlEngine?
I can use following snippet to load qml component from any data stream:
QUrl uri(...)
QByteArray data(...);
QQmlComponent::setData(data,uri);
but when passed component refers to another one (not already loaded), QmlEngine stopped because of missing resource.
Is there any event/callback where it is possible to handle such missing resource?
Added use-case scenario:
We're developing some QML visual components. Some components are implemented as .qml files
and some as QQuickItem
.
For example imagine following situation (it's very simplified):
QmlItem
"DiagramPoint", implemented in point.qmlQmlItem
"Line" implemented in line.qml, class is using "DiagramPoint" itemQQuickItem (c++)
"ConnectedLine" which internally using "Line" objectQmlProject
which using "ConnectedLine" components.
In case that point.qml and line.qml are located on hdd or stored inside Qt Resources, everything works automatically. But what we would like to achieve is to store these files in encrypted form in our internal .dat file
and decode it only on demand.
We're able to decode and load "Line" object from "ConnectedLine" implementation. But in case that "Line" (line.qml) depends on another encrypted file "DiagramPoint" (point.qml), this solution doesn't work.
Another possible solution
Another solution could be to register all decrypted .qml files on application startup and than use it. Something simillar to qmlRegisterType
which allows to register c++ QQuickItems
to QmlEngine
.
Unfortunately none of these methods allow to register Qml snippet from string buffer.
QQmlComponent
s are created from strings in memory, stored in the binary encrypted, but there doesn't seem to be a way to do that - it is like the QtQuick API was deliberately designed without a way to hide your code, not unless you pay for a commercial license and the QML compiler... – dtechQQmlComponent
from data, it doesn't seem to be possible to register it as a QML type that can be used in QML sources. In my case different components also depend on each other. – dtech