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. QML module Imports Not Found by IDE

QML module Imports Not Found by IDE

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlimportidewarningmodule
18 Posts 6 Posters 3.1k 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.
  • S Offline
    S Offline
    SimpleY
    wrote on 22 Oct 2024, 19:38 last edited by SimpleY
    #1

    The issue

    I get 2 false warnings in the Qt Creator IDE whenever I try to import the main QML module of my Qt Quick App project. This means the IDE fails to find and read the untitled module which means I can't use any auto-completion but I get annoying warnings if I access anything in the module instead.

    Here is the code of Main.qml, I only added import untitled in line 2:
    Main.qml

    CMakeLists.txt (literally completely untouched from the default one):

    project(untitled VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
    
    qt_standard_project_setup(REQUIRES 6.5)
    
    qt_add_executable(appuntitled
        main.cpp
    )
    
    qt_add_qml_module(appuntitled
        URI untitled
        VERSION 1.0
        QML_FILES
            Main.qml
    )
    
    # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
    # If you are developing for iOS or macOS you should consider setting an
    # explicit, fixed bundle identifier manually though.
    set_target_properties(appuntitled PROPERTIES
    #    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appuntitled
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    target_link_libraries(appuntitled
        PRIVATE Qt6::Quick
    )
    
    include(GNUInstallDirs)
    install(TARGETS appuntitled
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    

    As you can see there is clearly a QML module created with qt_add_qml_module with the URI untitled yet the IDE fails to recognize it. To confirm that this is really a so-called "false warning" just in the Qt Creator IDE itself, I am able to build and run the project just fine without changing anything, no errors during execution or compiling/building.

    Goal/Question

    I am simply trying to figure out how to properly inform the IDE of the module so that I can easily integrate C++ classes in the QML code while maintaining the smart code suggestion and auto-completion of QtCreator. I am very new to the Qt Creator and the Qt framework as a whole so I assume I am doing something wrong rather than this being a bug.

    Environment

    • Windows 10 64-bit
    • Qt Creator 14.0.2 (Community): all settings completely untouched
    • Qt 6.8.0 (no additional libraries used here)
    • Project: Qt Quick Application, untitled as project name, Kit: Destkop Qt 6.8.0 MinGW 64-bit with CMake

    Recreating the Issue

    All settings related to the project and environment are the default ones out of the box which makes recreating the issue very easy if necessary. Literally step by step guide of what I did to get that issue:

    • install Qt Creator 14.0.2 (Community) + Qt 6.8.0 + MinGW 13.1.0 64-bit on Windows 10 64-bit
    • open Qt Creator
    • press Create Project... in the Welcome page
    • select Application (Qt) > Qt Quick Application, press Choose...
    • leave name as untitled, for me the project location is C:\Users\MyUser\source\repos\Qt, press Next >
    • leave Details as default, press Next >
    • Kit as Desktop Qt 6.8.0 MinGW 64-bit, press Next >
    • press Finish
    • write import untitled in the second line of Main.qml
    • done, the warning appears...
    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sami Shalayel
      wrote on 23 Oct 2024, 13:14 last edited by
      #13

      Hello! From a quick look, it seems that your qmlls is not setup correctly and therefore can't find untitled. Could you try following steps and see if they resolve your issue?

      1. Pass the build folder to qmlls: you can do this via a variety of options (https://doc.qt.io/qt-6/qtqml-tooling-qmlls.html#setting-up-the-qml-language-server-in-your-editor) but I recommend setting the QT_QML_GENERATE_QMLLS_INI CMake variable to ON.
      2. Build the project: that generates the qmldir files etc (via the qt_add_qml_module) that qmlls needs to detect QML modules (and the .qmlls.ini files if you set QT_QML_GENERATE_QMLLS_INI to ON in the previous step)
      3. Restart the language server (using the language server button in the toolbar right above the QML text editor
        image.png )
      S T 2 Replies Last reply 23 Oct 2024, 15:22
      2
      • A Offline
        A Offline
        Axel Spoerl
        Moderators
        wrote on 22 Oct 2024, 20:12 last edited by
        #2

        import untitled tries to import something from the project's root directory. It doesn't find anything, because there's nothing to import, e.g. another QML file.
        Simply drop it and the warnings will disappear.

        Software Engineer
        The Qt Company, Oslo

        G S 2 Replies Last reply 22 Oct 2024, 21:01
        0
        • A Axel Spoerl
          22 Oct 2024, 20:12

          import untitled tries to import something from the project's root directory. It doesn't find anything, because there's nothing to import, e.g. another QML file.
          Simply drop it and the warnings will disappear.

          G Offline
          G Offline
          GrecKo
          Qt Champions 2018
          wrote on 22 Oct 2024, 21:01 last edited by
          #3

          @Axel-Spoerl hum ? import untitled tries to import the untitled module. There's no directory involved, at least not directly. Even with another file in the module, Qt C would complain.

          @SimpleY I'd suggest reporting this as an issue on https://bugreports.qt.io/secure/Dashboard.jspa , please post the link here after so we can follow.

          A 1 Reply Last reply 23 Oct 2024, 05:25
          0
          • A Axel Spoerl
            22 Oct 2024, 20:12

            import untitled tries to import something from the project's root directory. It doesn't find anything, because there's nothing to import, e.g. another QML file.
            Simply drop it and the warnings will disappear.

            S Offline
            S Offline
            SimpleY
            wrote on 22 Oct 2024, 21:18 last edited by SimpleY
            #4

            @Axel-Spoerl By drop I assume you mean delete the line? But the whole issue is about importing the main module which by default is named exactly as the project, here untitled as that's my project name. I am pretty sure the QML engine itself finds the module at runtime without issues because I explained the application builds & runs fine, so it's just the IDE as I see it and the code is fine too.

            @GrecKo So you think this is a bug too? I thought that originally but didn't dare to call it as such as I am a complete beginner in Qt to be honest. I will report it soon but https://bugreports.qt.io/secure/Dashboard.jspa doesn't work for me, says 503 Service Unavailable?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Axel Spoerl
              Moderators
              wrote on 22 Oct 2024, 23:55 last edited by
              #5

              @SimpleY
              untitled contains nothing but Main.qml here. Why should Main.qml import itself?

              Software Engineer
              The Qt Company, Oslo

              G 1 Reply Last reply 23 Oct 2024, 07:55
              0
              • G GrecKo
                22 Oct 2024, 21:01

                @Axel-Spoerl hum ? import untitled tries to import the untitled module. There's no directory involved, at least not directly. Even with another file in the module, Qt C would complain.

                @SimpleY I'd suggest reporting this as an issue on https://bugreports.qt.io/secure/Dashboard.jspa , please post the link here after so we can follow.

                A Offline
                A Offline
                Axel Spoerl
                Moderators
                wrote on 23 Oct 2024, 05:25 last edited by
                #6

                @GrecKo said in QML module Imports Not Found by IDE:

                Even with another file in the module, Qt C would complain.

                No, it clearly doesn't.

                Software Engineer
                The Qt Company, Oslo

                1 Reply Last reply
                0
                • A Axel Spoerl
                  22 Oct 2024, 23:55

                  @SimpleY
                  untitled contains nothing but Main.qml here. Why should Main.qml import itself?

                  G Offline
                  G Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on 23 Oct 2024, 07:55 last edited by GrecKo
                  #7

                  @Axel-Spoerl said in QML module Imports Not Found by IDE:

                  @SimpleY
                  untitled contains nothing but Main.qml here. Why should Main.qml import itself?

                  There's no particular reason to import it here, but it should still be possible.
                  The import working is not subject to it being useful...

                  @Axel-Spoerl said in QML module Imports Not Found by IDE:

                  No, it clearly doesn't.

                  Have you tried? I tried and it clearly does complain.
                  I've followed OP repro steps and added another QML file in the module and even went as far as using it in Main.qml so the import would be useful ;)

                  A 1 Reply Last reply 23 Oct 2024, 10:37
                  0
                  • G Offline
                    G Offline
                    GrecKo
                    Qt Champions 2018
                    wrote on 23 Oct 2024, 08:19 last edited by
                    #8

                    Building the project fixes the issue though (with or without another file).
                    If you don't actually use a type of the new module Qt Creator will complain about the "Unused import" but that's expected.

                    S 1 Reply Last reply 23 Oct 2024, 10:12
                    0
                    • G GrecKo
                      23 Oct 2024, 08:19

                      Building the project fixes the issue though (with or without another file).
                      If you don't actually use a type of the new module Qt Creator will complain about the "Unused import" but that's expected.

                      S Offline
                      S Offline
                      SimpleY
                      wrote on 23 Oct 2024, 10:12 last edited by
                      #9

                      @GrecKo For me nothing changes when I build it, the warnings remain the exact same. I also tried to do Tools > QML > Reset Codebade but it doesn't help. I could well imagine that this is just a bug in the newest version of Qt Creator or Qt framework, do you have the same environment as me installed?

                      1 Reply Last reply
                      0
                      • G GrecKo
                        23 Oct 2024, 07:55

                        @Axel-Spoerl said in QML module Imports Not Found by IDE:

                        @SimpleY
                        untitled contains nothing but Main.qml here. Why should Main.qml import itself?

                        There's no particular reason to import it here, but it should still be possible.
                        The import working is not subject to it being useful...

                        @Axel-Spoerl said in QML module Imports Not Found by IDE:

                        No, it clearly doesn't.

                        Have you tried? I tried and it clearly does complain.
                        I've followed OP repro steps and added another QML file in the module and even went as far as using it in Main.qml so the import would be useful ;)

                        A Offline
                        A Offline
                        Axel Spoerl
                        Moderators
                        wrote on 23 Oct 2024, 10:37 last edited by
                        #10

                        @GrecKo said in QML module Imports Not Found by IDE:

                        Have you tried? I tried and it clearly does complain.

                        Sure thing, I am doing that every day. But of course I never try to import a project containing nothing but its own Main.qml.
                        The issue here starts by including something that doesn't need to be included - and therefore shouldn't be.
                        The warnings disappear in the following cases:

                        • project contains something worth including, e.g. a QML extension written in C++
                        • unnecessary include statement is removed

                        The warning says "Failed to import untitled". To me, that's clear: Either there's nothing to import at all, or the import of something existing failed. It could be a suggestion in our bug tracker, to emit separate warnings:

                        • Nothing to import
                        • Failed to import (there is something

                        Software Engineer
                        The Qt Company, Oslo

                        G 1 Reply Last reply 23 Oct 2024, 11:55
                        0
                        • A Offline
                          A Offline
                          Axel Spoerl
                          Moderators
                          wrote on 23 Oct 2024, 10:54 last edited by Axel Spoerl
                          #11

                          You can have a look at the FX_Material_Showroom example to see how import syntax works.
                          Also look at this Jira ticket for reference.

                          Software Engineer
                          The Qt Company, Oslo

                          1 Reply Last reply
                          0
                          • A Axel Spoerl
                            23 Oct 2024, 10:37

                            @GrecKo said in QML module Imports Not Found by IDE:

                            Have you tried? I tried and it clearly does complain.

                            Sure thing, I am doing that every day. But of course I never try to import a project containing nothing but its own Main.qml.
                            The issue here starts by including something that doesn't need to be included - and therefore shouldn't be.
                            The warnings disappear in the following cases:

                            • project contains something worth including, e.g. a QML extension written in C++
                            • unnecessary include statement is removed

                            The warning says "Failed to import untitled". To me, that's clear: Either there's nothing to import at all, or the import of something existing failed. It could be a suggestion in our bug tracker, to emit separate warnings:

                            • Nothing to import
                            • Failed to import (there is something
                            G Offline
                            G Offline
                            GrecKo
                            Qt Champions 2018
                            wrote on 23 Oct 2024, 11:55 last edited by GrecKo
                            #12

                            @Axel-Spoerl said in QML module Imports Not Found by IDE:

                            The warning says "Failed to import untitled". To me, that's clear: Either there's nothing to import at all, or the import of something existing failed. It could be a suggestion in our bug tracker, to emit separate warnings:

                            • Nothing to import
                            • Failed to import (there is something

                            The first point is incorrect, the warning is there even when there's something to import (and even used).
                            And not having something else but Main.qml wouldn't warrant this. The module is there to import. The language server doesn't evaluate if a module is worth importing before importing, it just imports it. As confirmed by Qt Creator initially complaining but not after a build on my system with only Main.qml in the module (note that a clean reintroduces the warning).

                            @SimpleY said in QML module Imports Not Found by IDE:

                            @GrecKo For me nothing changes when I build it, the warnings remain the exact same. I also tried to do Tools > QML > Reset Codebade but it doesn't help. I could well imagine that this is just a bug in the newest version of Qt Creator or Qt framework, do you have the same environment as me installed?

                            I am also using Qt C 14.0.2 and Qt 6.8.0 but on Linux with GCC.
                            I do think this is worthy of a bug report, not sure if it will be high priority though. (EDIT: Axel mentioned this thread in the relevant Jira ticket, it is closed though).

                            1 Reply Last reply
                            1
                            • S Offline
                              S Offline
                              Sami Shalayel
                              wrote on 23 Oct 2024, 13:14 last edited by
                              #13

                              Hello! From a quick look, it seems that your qmlls is not setup correctly and therefore can't find untitled. Could you try following steps and see if they resolve your issue?

                              1. Pass the build folder to qmlls: you can do this via a variety of options (https://doc.qt.io/qt-6/qtqml-tooling-qmlls.html#setting-up-the-qml-language-server-in-your-editor) but I recommend setting the QT_QML_GENERATE_QMLLS_INI CMake variable to ON.
                              2. Build the project: that generates the qmldir files etc (via the qt_add_qml_module) that qmlls needs to detect QML modules (and the .qmlls.ini files if you set QT_QML_GENERATE_QMLLS_INI to ON in the previous step)
                              3. Restart the language server (using the language server button in the toolbar right above the QML text editor
                                image.png )
                              S T 2 Replies Last reply 23 Oct 2024, 15:22
                              2
                              • S Sami Shalayel
                                23 Oct 2024, 13:14

                                Hello! From a quick look, it seems that your qmlls is not setup correctly and therefore can't find untitled. Could you try following steps and see if they resolve your issue?

                                1. Pass the build folder to qmlls: you can do this via a variety of options (https://doc.qt.io/qt-6/qtqml-tooling-qmlls.html#setting-up-the-qml-language-server-in-your-editor) but I recommend setting the QT_QML_GENERATE_QMLLS_INI CMake variable to ON.
                                2. Build the project: that generates the qmldir files etc (via the qt_add_qml_module) that qmlls needs to detect QML modules (and the .qmlls.ini files if you set QT_QML_GENERATE_QMLLS_INI to ON in the previous step)
                                3. Restart the language server (using the language server button in the toolbar right above the QML text editor
                                  image.png )
                                S Offline
                                S Offline
                                SimpleY
                                wrote on 23 Oct 2024, 15:22 last edited by
                                #14

                                @Sami-Shalayel Oh my god thank you so much! This really worked like a charm, now I only get this warning but I am well aware that this is normal now...
                                136f3d35-b7d6-49aa-9757-f6b414471e24-image.png
                                All I had to do as you said is add set(QT_QML_GENERATE_QMLLS_INI ON) in the CMake file and rebuild.

                                So in the future I just have to set QT_QML_GENERATE_QMLLS_INI to ON in all of my projects or should I try to fix it another way?

                                1 Reply Last reply
                                0
                                • S SimpleY has marked this topic as solved on 23 Oct 2024, 20:38
                                • S Offline
                                  S Offline
                                  Sami Shalayel
                                  wrote on 24 Oct 2024, 08:34 last edited by
                                  #15

                                  If it works for you then Qt Creator can set it for you automatically on new projects if you check the checkbox at Preferences > Qt Quick > QML/JS Editing > Create .qmlls.ini files for new projects (see also https://doc.qt.io/qtcreator/creator-how-to-use-qml-language-server.html ). Its currently not checked by default because the current solution currently does not satisfy everyone (some people can't have .qmlls.ini files generated in their source folder for example), but there will be a solution to make it work out of the box in qt creator in the future.

                                  S 1 Reply Last reply 24 Oct 2024, 11:12
                                  1
                                  • S Sami Shalayel
                                    24 Oct 2024, 08:34

                                    If it works for you then Qt Creator can set it for you automatically on new projects if you check the checkbox at Preferences > Qt Quick > QML/JS Editing > Create .qmlls.ini files for new projects (see also https://doc.qt.io/qtcreator/creator-how-to-use-qml-language-server.html ). Its currently not checked by default because the current solution currently does not satisfy everyone (some people can't have .qmlls.ini files generated in their source folder for example), but there will be a solution to make it work out of the box in qt creator in the future.

                                    S Offline
                                    S Offline
                                    SimpleY
                                    wrote on 24 Oct 2024, 11:12 last edited by
                                    #16

                                    @Sami-Shalayel Hey, thank you again! That option is quite useful for new projects.

                                    If it's not too much to ask can you please also check out this issue since you seem to be familiar with QMLLS?

                                    1 Reply Last reply
                                    0
                                    • S SimpleY has marked this topic as solved on 25 Oct 2024, 11:23
                                    • S Sami Shalayel
                                      23 Oct 2024, 13:14

                                      Hello! From a quick look, it seems that your qmlls is not setup correctly and therefore can't find untitled. Could you try following steps and see if they resolve your issue?

                                      1. Pass the build folder to qmlls: you can do this via a variety of options (https://doc.qt.io/qt-6/qtqml-tooling-qmlls.html#setting-up-the-qml-language-server-in-your-editor) but I recommend setting the QT_QML_GENERATE_QMLLS_INI CMake variable to ON.
                                      2. Build the project: that generates the qmldir files etc (via the qt_add_qml_module) that qmlls needs to detect QML modules (and the .qmlls.ini files if you set QT_QML_GENERATE_QMLLS_INI to ON in the previous step)
                                      3. Restart the language server (using the language server button in the toolbar right above the QML text editor
                                        image.png )
                                      T Offline
                                      T Offline
                                      Tick info
                                      wrote on 15 Nov 2024, 11:54 last edited by
                                      #17

                                      @Sami-Shalayel
                                      hello ! I have been facing the same issue but I am using mac m4 and I tried what you mentioned in the comment. but it does not work.
                                      android architecture arm64v8a
                                      qt creator 6.8.0
                                      qt version same as mentioned in the problem.
                                      using "qmlRegisterType" to link the qt but as the problem says its throw warning and autocompletion is also not working.

                                      the same thing properly working in qt 6.7.2 but not in latest version

                                      guide me if you have solution.

                                      1 Reply Last reply
                                      0
                                      • L Offline
                                        L Offline
                                        Lazyplayer
                                        wrote on 20 Nov 2024, 08:14 last edited by
                                        #18

                                        @SimpleY i ve got same problem as your, try to go to preferences->Qt Quick->QML/JS editing-> QML Language server and remove tick on Tun on (leave all unchecked)

                                        it worked for me.

                                        1 Reply Last reply
                                        0

                                        5/18

                                        22 Oct 2024, 23:55

                                        13 unread
                                        • Login

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