module importation problem
-
Hi all -
I'm looking at an app with nested CMakeLists.txt files. The other developers are using VS Code to build this app, partly because they couldn't get Creator to work properly. Specifically, when the top-level CMake file is opened, Creator can't find one of our QML modules:
Strangely enough, when I open one of the subordinate CMake files, the problem doesn't occur:
I'm assuming this works because of this line in the CMake file:
list(APPEND QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/../libstyles)
But what I don't understand is, why is this showing as unfound when I open the top-level CMake file?
This is 5.14.2, BTW. Thanks for any ideas...
-
Qt Creator so often does not see imported modules that I'm usually surprised when it works ;-)
I have a few hints, but if they will help - no idea:
- add
libstyles
toQML_IMPORT_PATH
in the top-level cmake file - go to
Tools->QML/JS->Reset Code Model
this forces QtC to reparse files and refresh it's internal state - it sometimes helps in such situations - make sure you're using the newest Qt Creator and newest CMake
- add
-
Qt Creator so often does not see imported modules that I'm usually surprised when it works ;-)
I have a few hints, but if they will help - no idea:
- add
libstyles
toQML_IMPORT_PATH
in the top-level cmake file - go to
Tools->QML/JS->Reset Code Model
this forces QtC to reparse files and refresh it's internal state - it sometimes helps in such situations - make sure you're using the newest Qt Creator and newest CMake
@sierdzio thank you for the suggestions. I attempted to use the existing maintenance tool, and found to my surprise that there are no default repositories.
I've never had to add a repository before. Any idea what's going on here?
EDIT:
Anyway, I've downloaded 5.15.2 (had been using 5.14.2) and the newest Creator. Still getting the error. And what's really strange is, when I open the libstyles CMake file, the error goes away:
(The open file is within src/lib/libresources.qrc/qml; I didn't expand that folder because I wanted to show its relation to libstyles.)
Anyone have an idea on this? Thanks...
- add
-
@mzimmers said in module importation problem:
Anyway, I've downloaded 5.15.2 (had been using 5.14.2) and the newest Creator.
You can also download newest CMake using Qt Maintenance Tool, that's what I recommended actually.
And what's really strange is, when I open the libstyles CMake file, the error goes away
Ah, I think I've seen a similar behaviour. The workaround I use is this - each time I turn Qt Creator on, I right-click on project title (in left side pane) and select "Run CMake". This refreshes Qt Creator's cmake cache and stuff and it becomes suddenly more aware of the code.
-
@mzimmers said in module importation problem:
Anyway, I've downloaded 5.15.2 (had been using 5.14.2) and the newest Creator.
You can also download newest CMake using Qt Maintenance Tool, that's what I recommended actually.
And what's really strange is, when I open the libstyles CMake file, the error goes away
Ah, I think I've seen a similar behaviour. The workaround I use is this - each time I turn Qt Creator on, I right-click on project title (in left side pane) and select "Run CMake". This refreshes Qt Creator's cmake cache and stuff and it becomes suddenly more aware of the code.
@sierdzio I had in fact downloaded CMake 3.19.2 (forgot to mention this). Unfortunately, your workaround doesn't seem to work for me. I even tried running the CMake for src/lib and src/libstyles; no change.
I'm still trying to understand why opening the src/lib CMake project causes the error to go away. What might be happening when I open this project explicitly, that isn't happening when I open only the top-level project?
-
I don't know, sorry.
-
@mzimmers said in module importation problem:
QML_IMPORT_PATH
Actually, one more idea. Try setting correct path for
QML_IMPORT_PATH
in Project->Build in Qt Creator. I won't solve this for other developers but it might work on when set locally. -
@mzimmers said in module importation problem:
QML_IMPORT_PATH
Actually, one more idea. Try setting correct path for
QML_IMPORT_PATH
in Project->Build in Qt Creator. I won't solve this for other developers but it might work on when set locally.@sierdzio I think you're on to something here (though I haven't fixed it yet). In looking at the build settings, it appears that the QML_IMPORT_PATH variable is populated by this line in build/CMakeCache.txt:
QML_IMPORT_PATH:STRING=/home/mzimmers/git/KOL-UI/qml;/home/mzimmers/git/KOL-UI/qml/dummydata;/home/mzimmers/git/KOL-UI/qml/priming;/home/mzimmers/git/KOL-UI/qml/running_synth;/home/mzimmers/git/KOL-UI/../libstyles;/home/mzimmers/git/KOL-UI/../libstyles/imports;/home/mzimmers/git/KOL-UI/../libstyles/imports/libstyles;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/imports
I replaced a few entries to what I believe are correct paths:
QML_IMPORT_PATH:STRING=/home/mzimmers/git/KOL-UI/qml;/home/mzimmers/git/KOL-UI/qml/dummydata;/home/mzimmers/git/KOL-UI/qml/priming;/home/mzimmers/git/KOL-UI/qml/running_synth;/home/mzimmers/git/KOL-UI/src/libstyles;/home/mzimmers/git/KOL-UI/src/libstyles/imports;/home/mzimmers/git/KOL-UI/src/libstyles/imports/libstyles;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/bin;/home/mzimmers/git/KOL-UI/build/imports;/home/mzimmers/git/KOL-UI/build/imports
And I re-ran CMake, but this didn't solve the problem. I went ahead and manually changed the build settings, and this did solve the problem, though I imagine the next time I do whatever causes the CMakeCache.txt file to be re-read will wipe out those changes.
EDIT:
So, with the help of someone in the office, we figured out what to do here. This line (among others) was in the subordinate CMake file; we just moved it to the root CMake file:
list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/libstyles)
I'm not sure it was necessary to use CMAKE_CURRENT_SOURCE_DIR instead of CMAKE_SOURCE_DIR in this instance, but it's probably a good practice.
Thanks for the help...