[SOLVED] Import directory in QML

  • 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: {

        id: yo
        MouseArea {
            anchors.fill: parent
            onClicked: {


    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.

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

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

    Then you should be able to use:


  • 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 :(

  • Qt Champions 2017

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

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.