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

Unable to load from qrc after "Add new... (QML file)" 🍀



  • I created a very basic application (MWE). I'm not able to create my own QML file and subsequently import it into main.qml.

    702899d3-c5da-4d6c-9cb6-86563a59ed8d-image.png

    QMLSide.qml:

    import QtQuick 2.12
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.3
    
    Frame {
        ListView {
            implicitWidth: 250
            implicitHeight: 250
            model: 100
            delegate: RowLayout {
                CheckBox {}
                TextField {}
            }
        }
    }
    

    main.qml:

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    import "QMLSide.qml"
    
    ApplicationWindow {
        visible: true
        width: 300
        height: 120
        title: qsTr("Hello World")
    
          MyListView {
    
          }
    
    }
    

    See screenshot for errors but it says:

    qrc:/main.qml:3 "QMLSide.qml": no such directory
     qml\qqmlapplicationengine.cpp: 132
    

    Any ideas how to get it to import properly?


  • Moderators

    @enjoysmath said in Unable to load from qrc after "Add new... (QML file)" 🍀:

    Any ideas how to get it to import properly?

    Do not import anything, just use it.

    QML engine always scans the current directory - all files in the same directory as main.qml are automatically available and recognized.

    You only need to use import when your QML code is in a different directory, and you should only specify the directory path, not file path.


  • Moderators

    @enjoysmath said in Unable to load from qrc after "Add new... (QML file)" 🍀:

    Any ideas how to get it to import properly?

    Do not import anything, just use it.

    QML engine always scans the current directory - all files in the same directory as main.qml are automatically available and recognized.

    You only need to use import when your QML code is in a different directory, and you should only specify the directory path, not file path.



  • Thanks @sierdzio that was very helpful! :)


Log in to reply