(reopened) using subdirectories in a CMake project
-
Interesting...I always thought a plug-in was something available separately, that the host program wouldn't even know of until it was added. In this example, we're creating (and linking) a static library, which to my novice mind doesn't seem very much like a plugin.
@mzimmers said in using subdirectories in a CMake project:
Interesting...I always thought a plug-in was something available separately, that the host program wouldn't even know of until it was added.
That's why I said in my previous post: Depends on how you define a "true plugin".
This is definitely implemented using the plugin interface, but it doesn't "feel" like a plugin. The host program does load the plugin code at runtime even though even though the plugin library is statically-linked.
-
Interesting...I always thought a plug-in was something available separately, that the host program wouldn't even know of until it was added. In this example, we're creating (and linking) a static library, which to my novice mind doesn't seem very much like a plugin.
@mzimmers said in using subdirectories in a CMake project:
Interesting...I always thought a plug-in was something available separately, that the host program wouldn't even know of until it was added. In this example, we're creating (and linking) a static library, which to my novice mind doesn't seem very much like a plugin.
To elaborate a bit more. Yes, but that's because you chose to build statically. I believe the recommended way is to stick to dynamic QML modules still. In any case, you can have static plugins, it's not unheard of, it's just somewhat unusual - think Qt's image formats for example. If you build Qt statically these are linked in statically as well (and they need to be initialized separately, in Qt5 times you also did this manually).
https://doc.qt.io/qt-6/plugins-howto.html#static-plugins
https://doc.qt.io/qt-6/qtplugin.html#Q_IMPORT_PLUGIN -
@mzimmers said in using subdirectories in a CMake project:
Interesting...I always thought a plug-in was something available separately, that the host program wouldn't even know of until it was added. In this example, we're creating (and linking) a static library, which to my novice mind doesn't seem very much like a plugin.
To elaborate a bit more. Yes, but that's because you chose to build statically. I believe the recommended way is to stick to dynamic QML modules still. In any case, you can have static plugins, it's not unheard of, it's just somewhat unusual - think Qt's image formats for example. If you build Qt statically these are linked in statically as well (and they need to be initialized separately, in Qt5 times you also did this manually).
https://doc.qt.io/qt-6/plugins-howto.html#static-plugins
https://doc.qt.io/qt-6/qtplugin.html#Q_IMPORT_PLUGIN@kshegunov said in using subdirectories in a CMake project:
I believe the recommended way is to stick to dynamic QML modules still.
I haven't seen an official recommendation on this. Got a link?
Anyway, I recommended a static plugin in this case because @mzimmers's goal is to organize his QML code into subfolders.
- Qt 5 way: Manually write a
qmldir
file and stick the *.qml + qmldir files inside a QRC resource to be embedded into the main app - Qt 6 way: Let
qt_add_qml_module()
auto-generate aqmldir
file and auto-generate a static plugin to be embedded into the main app
(There are other ways to use subfolders in the source code; these are my preferences)
I would recommend a dynamic plugin if the goal is to create a standalone, reusable module that is to be used by multiple other apps.
- Qt 5 way: Manually write a
-
So, I thought I had this working, but I just tried running my app on an Android emulator, and got an error that one of my custom Components is not a type. Is there a nuance to the build process I'm missing, or should I ask this in the Mobile forum?
Thanks...
-
So, I thought I had this working, but I just tried running my app on an Android emulator, and got an error that one of my custom Components is not a type. Is there a nuance to the build process I'm missing, or should I ask this in the Mobile forum?
Thanks...
@mzimmers said in (reopened) using subdirectories in a CMake project:
got an error that one of my custom Components is not a type
You mean it didn't complain that your import was unrecognized, but if complained that your type is unrecognized? That's a bit strange.
Posting some sample code would be helpful.
I'd expect it to behave the same on both Android and on Desktop; it would be a bit simpler to troubleshoot on a Desktop target.
-
@mzimmers said in (reopened) using subdirectories in a CMake project:
got an error that one of my custom Components is not a type
You mean it didn't complain that your import was unrecognized, but if complained that your type is unrecognized? That's a bit strange.
Posting some sample code would be helpful.
I'd expect it to behave the same on both Android and on Desktop; it would be a bit simpler to troubleshoot on a Desktop target.
@JKSH yeah, it works fine for the desktop, just not for Android.
What code do you want to see? Here's the Android-specific part of my CMakeLists.txt file:
set( ANDROID_PACKAGE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/android CACHE INTERNAL "" ) set_property(TARGET appqmltest APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
-
@JKSH yeah, it works fine for the desktop, just not for Android.
What code do you want to see? Here's the Android-specific part of my CMakeLists.txt file:
set( ANDROID_PACKAGE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/android CACHE INTERNAL "" ) set_property(TARGET appqmltest APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
@mzimmers said in (reopened) using subdirectories in a CMake project:
What code do you want to see?
Ideally, a minimal, compilable project (with any sensitive info removed) that works fine on the desktop but doesn't work on Android. Some ways to do this include:
- Zip up the project, upload it to a file sharing server and post a link here, OR
- Publish your project in a code repository (like GitHub) and post a link here
Here's the Android-specific part of my CMakeLists.txt file:
set( ANDROID_PACKAGE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/android CACHE INTERNAL "" ) set_property(TARGET appqmltest APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
While I haven't developed a QML project for Android in a while, this part doesn't look like a problem.
-
https://github.com/mzimmers/demo/blob/main/nga_demo.7z
It's not a minimal example, but the only part that matters (I think) is the "custom" subproject as mentioned in the main CMakeLists.txt.
Thanks...
-
https://github.com/mzimmers/demo/blob/main/nga_demo.7z
It's not a minimal example, but the only part that matters (I think) is the "custom" subproject as mentioned in the main CMakeLists.txt.
Thanks...
@mzimmers said in (reopened) using subdirectories in a CMake project:
Ah, ok. It looks like QQmlApplicationEngine doesn't actually try to import modules from the QRC root. Add
engine.addImportPath(":/");
before your load main.qml.It works on the Desktop because the application was loading your custom module from your build folder. Android can't do that. (It will also not work if you deploy the application to a different Desktop PC)
P.S. In the future, please push code directly to GitHub; please don't upload a zip file of your code on GitHub.
-
@mzimmers said in (reopened) using subdirectories in a CMake project:
Ah, ok. It looks like QQmlApplicationEngine doesn't actually try to import modules from the QRC root. Add
engine.addImportPath(":/");
before your load main.qml.It works on the Desktop because the application was loading your custom module from your build folder. Android can't do that. (It will also not work if you deploy the application to a different Desktop PC)
P.S. In the future, please push code directly to GitHub; please don't upload a zip file of your code on GitHub.
-
J JKSH referenced this topic on