How to know which version of QML module is loaded? - qt

I want to check which version of a QtQuick module has been loaded.
There is an environment variable QML_IMPORT_TRACE you can set to display debugging info about the imports. I set it to 1 in the QtCreator project and got details in the console, mostly the path of the libs.
QQmlImportDatabase::addImportPath:
"/QT_INSTALL/5.9.3/gcc_64/qml"
QQmlImportDatabase::addImportPath: "qrc:/qt-project.org/imports"
QQmlImportDatabase::addImportPath: "/home/PROJECT_FOLDER"
QQmlImports(qrc:/main.qml)::addLibraryImport: "QtQuick" 2.0 as ""
QQmlImports(qrc:/main.qml)::importExtension: loaded
"/QT_INSTALL/5.9.3/gcc_64/qml/QtQuick.2/qmldir"
QQmlImportDatabase::registerPluginTypes: "QtQuick" from
"/QT_INSTALL/5.9.3/gcc_64/qml/QtQuick.2"
...
Based on the path of the installation you probably can guess the version of QtQuick from the Qt version...
But is there any direct way to display the exact module version at runtime?
(and ideally without debugging the imports)

Related

Qt 6.4.1, no Qt6Multimedia folder present - CMakeLists.txt can't find the module

I am using Qt 6.4.1, and in QtCreator I am trying to import the Qt6 Multimedia module, but I get the following error:
The error says "Found package configuration file: C:/Qt/qt/6.4.1/mingw_64/lib/cmake/Qt6/Qt6Config.cmake but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT FOUND. Reason given by package: Failed to find required Qt component "Multimedia". Expected config file at "C:/Qt/qt/6.4.1/mingw_64/lib/cmake/Qt6Multimedia/Qt6MultimediaConfig.cmake" does NOT exist"
It appears my Qt version does not have the folder in my cmake directory:
Why is this? Have I missed something/got something wrong or is there no support for the Multimedia module in Qt6.4.1? What can I do to import this module? Thanks in advance.
You need to check QtMultimedia in QtMaintenanceTool when you are installing Qt. See the screenshot:
If it is not available for your compiler, then you have no other option than build Qt with QtMultimedia on your own.

macdeployqt does not copy the QtWebView plugin

I could not find a way to inform macdeployqt that I need QT_ROOT/qml/QtWebView/libdeclarative_webview.dylib to be copied into the app bundle. This is needed to use native QtWebView in QML (configured with QT_WEBVIEW_PLUGIN=native). Is there a way to avoid manual copying and rely on macdeployqt instead?
Note that the library QT_ROOT/plugins/webview/libqtwebview_darwin.dylib is correctly recognized and included in the bundle.
The project is built with cmake, Qt version is 5.15.2. Essential steps are shown below.
find_package(Qt5 REQUIRED COMPONENTS ... WebView)
target_link_libraries(${binary} ... Qt5::WebView)
execute_process(
COMMAND ${qt_root}/bin/macdeployqt
${CMAKE_INSTALL_PREFIX}/bin/my_app_bundle.app
-qmldir=${qt_root}/qml
)
The issue was in misusing qmldir and qmlimport. Correct invocation is
execute_process(
COMMAND ${qt_root}/bin/macdeployqt
${CMAKE_INSTALL_PREFIX}/bin/my_app_bundle.app
-qmldir=${CMAKE_CURRENT_SOURCE_DIR}/quick_ui
-qmlimport=${qt_root}/qml
)

Where does the Qt sqlite plugin look for extension libraries

I have made the appropriate modification as found in this thread to enable the Qt sqlite plugin to load extensions. However, when I run SELECT load_extension('spatialite_mod'), I now get the error The specified module could not be found
On a Windows Qt installation, where do I need to put the spatialite_mod.dll file so that it can be found a runtime? I have already tried putting it in the binary directory without any success.
This turned out to be a multi-part problem.
The answer to the original question is that Qt looks for the libraries in the working directory (QDir::currentPath()) and in the Windows PATH.
Part 1:
On Windows, the specified module could not be found error also can mean that one of mod_spatialite.dll dependencies was not found. In my case, I had forgotten to move these dependencies to the same directory as mod_spatialite.dll. They include:
libgcc_s_dw2-1.dll
libstdc++-6.dll
libsqlite3-0.dll
libxml2-2.dll
zlib1.dll
libfreexl-1.dll
libgeos_c-1.dll
libgeos-3-5-0.dll
libiconv-2.dll
liblzma-5.cll
libproj-9.dll
Part 2:
The libgcc_s_dw2-1.dll and libstdc++-6.dll libraries shipped with libspatialite do not work with Windows 10. Read more about this here and here. They would crash the program when loaded. The fix for me was to grab the same libraries from my Qt installation at C:\Qt\5.11.3\mingw53_32.

windeployqt module QtQuick not installed [duplicate]

This question already has answers here:
Deploy Qt5 QML application
(8 answers)
Closed 4 years ago.
Im trying to deploy a set of QT applications. On linux all applications works fine after installing all dependencies, but in windows QtQuick based applications doesn't work at all.
To deploy on windows I follow this steps:
Compile my project in release mode.
Add mingw to the system environment path
Run windeployqt.exe --release c:\myappdir\relesase\myapp.exe
When step 3 is finish I got a lot of dlls in the release folder Qt5Quick.dll among them. But myapp.exe doesn't work and didn't threw any error.
In order to get any extra information I add console to my CONFIG parameter under myapp.pro file and running myapp.exe by console I got this info:
QQmlApplicationEngine failed to load component
qrc:/main.qml:1 module "QtQuick" is not installed
qrc:/main.qml:-1 module "QtQuick" is not installed
qrc:/main.qml:1 module "QtQuick" is not installed
My version of QtSDK is 5.10.0 with MinGW so this solution doesn't work at all, I got more errors.
More over if I try to run myapp.exe without those dll in the root folder it works fine.
I been the whole day trying to find any solutions but nothing seems to work.
I'm pretty sure I missing something but I don't know whats is it.
Thanks
As I suppose, I was missing something. --qmldir option is needed in order to add QtQuick modules.
windeployqt.exe --qmldir . --release c:\myappdir\relesase\myapp.exe
That line did the trick,
Thanks #frank osterfeld and #Felix

How to find the latest versions of all QML modules

Usually my QML files start with import QtQuick 2.4 and other imports. How can I know which is the latest version of the imported modules without having to guess by type and build?
You basically don't have to know. By importing a particular version, you merely declare that you don't need the additional functionality of any potentially newer version. That doesn't mean that you won't use a newer version if one is available - it simply means that your code will refuse to run if only an older version than the one you need is present.
So, you should only change the imported module version if you happen to use the functionality (members, classes, etc.) from a newer version. That's all. And you will know exactly what version you need, since you're using the functionality you read about in the documentation. The documentation will state what module version it applies to.
The documentation for a given Qt Quick module from the Qt that you're using will state this - no need for release notes.
The QML module version information can be found in a file called plugins.qmltypes.
These files use JSON to store information (as far as I am aware).
In these files Qt uses the "exports" specifier to export the name and version of a module.
Example:
exports: ["QtQuick/Accessible 2.0"]
The example shows the version of the QtQuick.Accessible module.
The plugins.qmltypes are stored in a directory of the same name as base level module.
In the case of the example this would be QtQuick.
Base level modules are grouped under a directory titled qml.
That is "usually" located in a directory called qtx (in some case Qt).
Where x is the installed major version of Qt (in my case it would be qt5).
That means the plugins.qmltypes has a path that looks something like this:
/qt5/qml/QtQuick/plugins.qmltypes
The reason im explaining this bottoms up cause the rest of the path is dependent on how you installed Qt:
Package manager (portage) amd64 install path:
/usr/lib64/qt5/qml/
pip PySide6 install path:
~/.local/lib/python3.9/site-packages/PySide6/Qt/qml/
pip PyQt6 install path:
~/.local/lib/python3.9/site-packages/PyQt6/Qt6/qml
~/.local/lib/python3.9/site-packages/PyQt6/Qt6/qml
Package manager (apt) aarch64 install path:
/usr/lib64/aarch64-{forgot this part}-/qt5/qml/
I figure the version out in bulk with:
grep -r "exports:.*\\]" <insert install/OS dependent path>/qml/* | less
This doesnt grab multiple exports that are spread over multiple lines thought.
Since QML comes in 2 major versions when in doubt you could import version 1.0 or 2.0.

Resources