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. [SOLVED] Import directory in QML
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Import directory in QML

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 3.6k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    Qnoobish
    wrote on last edited by
    #1

    Hello,

    I've been reading the documentation on importing directories in QML: http://qt-project.org/doc/qt-5/qtqml-syntax-directoryimports.html
    and what I am trying to do is not working.

    I have a QML file that imports an absolute path in another drive:

    @import QtQuick 2.0
    import "D:/My Documents/SametimeFileTransfers/importsTest/Level3/"

    Rectangle {
    width: 800
    height: 600
    Text {
    anchors.centerIn: parent
    text: "Hello World"
    }
    MouseArea {
    anchors.fill: parent
    onClicked: {

        }
    }
    
    Cuadro{
        id: yo
        color:"red"
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                yo.color="yellow";
                yo.cambia("hola");
            }
        }
    }
    

    }
    @

    According to the documentation, importing an absolute path is available but it's not working for me.

    So I don't know if importing a directory in another drive will work. Right now I have the file "main.qml" located somewhere in drive C: and I would like to import a QML directory located in drive D:

    If this is possible how can i handle this import?

    Any comment regarding this issue is appreciated.

    Thanks in advance.

    In short, software is eating the world.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cmazieri
      wrote on last edited by
      #2

      Try to use import <dir> as name, example:

      import "D:/My Documents/SametimeFileTransfers/importsTest/Level3/" as level3

      Then you should be able to use:

      level3.<some-file-there>

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qnoobish
        wrote on last edited by
        #3

        Hello, thanks for your reply.

        I tried to import the directory and place an identifier or local namespace, as you explained, but it's also not working :(

        In short, software is eating the world.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          This directory is outside the qml main files. Try to use QMLEngine.addImportPath(...) and qmldir to define the QML components.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Qnoobish
            wrote on last edited by
            #5

            My problem is solved if I use the following syntax:

            @import "file:///D:/QML_Modules"@

            If the "file:///" part is used, my path gets imported.

            Hopefully this would help someone else.

            I'll mark this thread as solved.

            In short, software is eating the world.

            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