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. import qml error:no such directory
QtWS25 Last Chance

import qml error:no such directory

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 3 Posters 71 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.
  • C Offline
    C Offline
    cuijg
    wrote last edited by
    #1

    c9ef9a07-bd94-42ac-8868-47658924296e-image.png
    5be2eba2-337f-418b-a92d-f3b1432a7f7f-image.png
    ffaa90e9-7f2f-4e3d-afb6-db49116aa52c-image.png
    4467f170-56f9-49f4-9590-79b6f675888b-image.png
    8afba58e-43a6-4d2f-8878-62ce933bbc1f-image.png

    S 1 Reply Last reply
    0
    • S Offline
      S Offline
      Shrishashank
      wrote last edited by
      #2

      Look at the error in QQmlApplicationEngie failed means path is not properly Set....

      SHRISHASHANK S K

      1 Reply Last reply
      0
      • C cuijg

        c9ef9a07-bd94-42ac-8868-47658924296e-image.png
        5be2eba2-337f-418b-a92d-f3b1432a7f7f-image.png
        ffaa90e9-7f2f-4e3d-afb6-db49116aa52c-image.png
        4467f170-56f9-49f4-9590-79b6f675888b-image.png
        8afba58e-43a6-4d2f-8878-62ce933bbc1f-image.png

        S Offline
        S Offline
        Shrishashank
        wrote last edited by Shrishashank
        #3

        @cuijg Also tell me exactly what are you trying to do ?Please Brief More

        SHRISHASHANK S K

        JonBJ 1 Reply Last reply
        0
        • S Shrishashank

          @cuijg Also tell me exactly what are you trying to do ?Please Brief More

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by
          #4

          @Shrishashank
          The OP is clearly asking why import "../Constants.qml" fails to find that file in the directory immediately above where App.qml lives, given the hierarchical directory structure in the screenshots.

          S 1 Reply Last reply
          0
          • JonBJ JonB

            @Shrishashank
            The OP is clearly asking why import "../Constants.qml" fails to find that file in the directory immediately above where App.qml lives, given the hierarchical directory structure in the screenshots.

            S Offline
            S Offline
            Shrishashank
            wrote last edited by
            #5

            @JonB Got it Jon ,The thing is I also getting the same issue, but intead of QCoreApplication::applicatioDirpath() i given the hardcode path where it works for me ,but this way is also good and also taking the absolute path of the Dir,
            Thank you for you Input .

            SHRISHASHANK S K

            JonBJ 1 Reply Last reply
            0
            • S Shrishashank

              @JonB Got it Jon ,The thing is I also getting the same issue, but intead of QCoreApplication::applicatioDirpath() i given the hardcode path where it works for me ,but this way is also good and also taking the absolute path of the Dir,
              Thank you for you Input .

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote last edited by JonB
              #6

              @Shrishashank
              I know nothing about QML so cannot answer the question. But this is an import statement in code. Clearly that cannot use a hard-coded, absolute path as it must work from anywhere. Nor can QCoreApplication::applicatioDirpath() or similar be used in an import statement. It seems clear a relative path would be required. But the OP says ../Constants.qml, which looks to be correct (if QML allows it) to reach that file from where App.qml is, apparently does not find it.

              @cuijg
              Your situation is reported in e.g. https://forum.qt.io/topic/98165/import-with-relative-path. There the OP fails on ... The solution there claims you are supposed to write

              import ":/../Constants.qml"
              

              Note the leading :/. Try that?

              [UPDATE: Sorry, no, that appears to be for a resource file, like an icon, not a source code file.]

              However I note that seems in contradiction to Qt docs at https://doc.qt.io/qt-6/qtqml-syntax-directoryimports.html, which does imply your plain ../... should work. As I said, I know nothing :) So good luck.

              C 1 Reply Last reply
              0
              • JonBJ JonB

                @Shrishashank
                I know nothing about QML so cannot answer the question. But this is an import statement in code. Clearly that cannot use a hard-coded, absolute path as it must work from anywhere. Nor can QCoreApplication::applicatioDirpath() or similar be used in an import statement. It seems clear a relative path would be required. But the OP says ../Constants.qml, which looks to be correct (if QML allows it) to reach that file from where App.qml is, apparently does not find it.

                @cuijg
                Your situation is reported in e.g. https://forum.qt.io/topic/98165/import-with-relative-path. There the OP fails on ... The solution there claims you are supposed to write

                import ":/../Constants.qml"
                

                Note the leading :/. Try that?

                [UPDATE: Sorry, no, that appears to be for a resource file, like an icon, not a source code file.]

                However I note that seems in contradiction to Qt docs at https://doc.qt.io/qt-6/qtqml-syntax-directoryimports.html, which does imply your plain ../... should work. As I said, I know nothing :) So good luck.

                C Offline
                C Offline
                cuijg
                wrote last edited by
                #7

                @JonB This path ':/xxx/...' is not allowed. I even added the qrc resource file and the qml file, and then imported 'qrc:/xxx. qml', but still couldn't find the qml file. I'm powerless now

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cuijg
                  wrote last edited by
                  #8

                  I succeeded, but it looks very strange:
                  Step 1: Add to CMakeLists.txt:
                  set_source_files_properties(Constants.qml
                  PROPERTIES
                  QT_QML_SINGLETON_TYPE TRUE
                  )
                  Step 2: There is no need to explicitly reference Constants.qml in App. qml

                  As a result, the operation was successful

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cuijg
                    wrote last edited by
                    #9

                    This import does not import a file, but a directory, which is why the above error is always reported: no such directory

                    I understand a little bit now. The use of qml is like the classes and objects of c++. What are defined in the qml file are types. When using them, they cannot be directly referenced by the type name (unless a singleton object is defined). Instead, an object instance should be created using the type defined in qml, and then this instance object should be referenced.
                    For example:
                    abbe001d-1548-4c43-9091-4daf55ce67f7-image.png
                    d236e0a6-423c-437f-8882-5d4359082db5-image.png
                    def18adc-3d9c-42ce-be41-70785efe898f-image.png

                    1 Reply Last reply
                    0
                    • C cuijg has marked this topic as solved

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved