Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem using a QML plugin from Application
Forum Updated to NodeBB v4.3 + New Features

Problem using a QML plugin from Application

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stevemcgf
    wrote on last edited by stevemcgf
    #1

    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 directory

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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevemcgf
      wrote on last edited by
      #2

      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.

      JianJianJ 1 Reply Last reply
      4
      • S stevemcgf

        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.

        JianJianJ Offline
        JianJianJ Offline
        JianJian
        wrote on last edited by
        #3

        @stevemcgf thanks for your answer, just slove my problem!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved