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. Unable to load from qrc after "Add new... (QML file)" 🍀
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 615 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by enjoysmath
    #1

    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?

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      5
      • enjoysmathE Offline
        enjoysmathE Offline
        enjoysmath
        wrote on last edited by
        #3

        Thanks @sierdzio that was very helpful! :)

        https://github.com/enjoysmath
        https://math.stackexchange.com/users/26327/exercisingmathematician

        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