Solved Problem using a QML plugin from Application
-
I have a simple plugin definition mixing C++ and QML components. The resulting plugin works with qmlplugindump
void GuiUtilsPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String(GUIQMLPLUGIN_URI)); // C++ qmlRegisterType<EcKernelChart>(uri, 1, 0, "EcKernelChart"); // QML qmlRegisterType(QUrl("qrc:/khuska.gui/styles/SimpleLabel.qml"), uri, 1, 0, "SimpleLabel"); }
Now, when I try to use it with another app and load the plugin like this:
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.addImportPath(QStringLiteral(QML_IMPORT_PATH)); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
The plugin loads right as I can see debuging messages of the qmlRegisterType calls but when I load de main.qml that have a reference to SimpleLabel I have this error:
QQmlApplicationEngine failed to load component
qrc:/main.qml:15 Type SimpleLabel unavailable
qrc:/khuska.gui/styles/SimpleLabel.qml:-1 No such file or directorythe main.qml is very simple just this:
import QtQuick 2.8 import QtQuick.Window 2.2 import khuska.Gui 1.0 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") EcKernelChart { } SimpleLabel { } }
Anyone know what I'm doing wrong here?
Thanks.
-
After digging around I found a similar problem in other forum post. My problem was in the name of my resource file. If you have the same resource file name in your library and your application (in my case was qml.qrc) one will shadow the other,
So the fix was as simple as renaming the file qml.qrc to myplugin_qml.qrc
Sorry for not taking more time searching for the answer but I was stuck in this problem for almost two days.