Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Issue using QQuickWidget with a resource qml file in a plugin



  • Hi,

    I'm currently developing an application loading several plugins (based on Qt plugins documentation).
    Each plugin is creating a widget with a function like this one:

    QWidget* createWidget();
    

    Everything worked fine and widgets were created and displayed until I decided to.. return a QQuickWidget !
    I set its source to a qml file in a resource file (with a different name from other plugins' resource files to avoid conflict):

    this->setSource(QUrl(":/qml/MyQmlFile.qml"));
    

    and the widget returned an error (when loaded in the main application): "file:///path/to/my/app/executable/: file to open is a directory"

    Futher information:

    QFile file(QUrl(":/qml/MyQmlFile.qml"));
    file.open(QIODevice::ReadOnly); // returns true
    
    this->setSource(QUrl("/path/to/my/plugin/qml/MyQmlFile.qml")); // works fine
    

    Any ideas why QQuickWidget won't load my qml file when in a resource file ?



  • Solution is to use:

    this->setSource(QUrl("qrc:/qml/MyQmlFile.qml"));
    

    QUrl apparently needs qrc:/ and not just :/


Log in to reply