QML module Imports Not Found by IDE
-
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:
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 URIuntitled
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...
-
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?
- 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.
- 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)
- Restart the language server (using the language server button in the toolbar right above the QML text editor
)
-
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. -
@Axel-Spoerl hum ?
import untitled
tries to import theuntitled
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.
-
@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?
-
@SimpleY
untitled
contains nothing butMain.qml
here. Why shouldMain.qml
import itself? -
@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.
-
@Axel-Spoerl said in QML module Imports Not Found by IDE:
@SimpleY
untitled
contains nothing butMain.qml
here. Why shouldMain.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 ;) -
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. -
@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?
-
@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
-
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. -
@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). -
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?
- 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.
- 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)
- Restart the language server (using the language server button in the toolbar right above the QML text editor
)
-
@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...
All I had to do as you said is addset(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
toON
in all of my projects or should I try to fix it another way? -
-
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.
-
@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?
-
-
@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.
-
@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.