Runtime QML type in Qt Design Studio?
-
@fear2137 I started typing this answer (below), and I got almost finished answering when I realized that it might not help.
My answer definitely applies for objects supplied to QML from C++ using
QQmlContext::setContextProperty
, but I'm actually (I now realize) not at all certain whether it works with objects supplied viaqmlRegisterType
.I'm going to share my answer anyway, because if you didn't know about "dummydata" then this will almost certainly be relevant to you at some point.
For me, it would still be "homework" or a further investigatory exercise to see whether and how this would help with
qmlRegisterType
.The problem is one that might be solved with "dummydata."
Caveat: I use
qmlscene
by launching it directly from a bash terminal prompt. I don't use Qt Design Studio. But I think that both are ultimately usingqmlscene
under the hood."dummydata" is a folder name that is hardcoded in the source code for qmlscene. You can verify that here:
- https://github.com/qt/qtdeclarative/blob/1ff2d96d863be027ebed333fb0b441fa051c7cba/tools/qmlscene/main.cpp#L297
- https://github.com/qt/qtdeclarative/blob/1ff2d96d863be027ebed333fb0b441fa051c7cba/tools/qml/main.cpp#L356
When qmlscene renders your QML, it will look in the "dummydata" folder and load QML objects that you can name with identical names to what you would otherwise supply in C++.
Someone in another forum with a similar issue:
Some more info on dummydata: https://doc.qt.io/qt-5/qtquick-qmlscene.html#loading-test-data
If you also build your own Qt plugin dynamic libraries (using, for example,
CONFIG += plugin
in qmake*.pro
project), then you might need extra arguments toqmlscene
so that the QML from your plugin source folder is used. Here is one example of those arguments: -
@KH-219Design I have created my own plugin, and it is recognized by Qt Design Studio QML editor but when I run the app it gives me Cannot load library: The specified module could not be found error
-
@fear2137 Based on some superficial searching I just did, it seems that
"The specified module could not be found."
and the corresponding codeERROR_MOD_NOT_FOUND
are specific to Qt on Microsoft Windows, and that is the platform that I spend the least time with, so (combined with the fact that I don't use Design Studio) I probably can't help further. Hopefully someone else will know.Based on similar issues I have seen, I would hypothesize that both of the following might be worth investigating:
- is it possible to put your own plugin "somewhere" where it will be found at launch (I am sure you are trying this already), but also...
- Consider the possibility that Qt is finding your plugin, but that subsequently Qt is unable to locate further
dll
files that your plugin transitively depends on.
That option (2) has caught me by surprise in the past. Option (2) also seems to be suggested by these:
-
@KH-219Design I did a hack by turning the dll name into exe and ran windeployqt to copy all needed modules, I then copied everything to the module folder in project but still error remains.