QML plugins not working in static build
-
I've been porting a project from Qt 5.12 to 6.5. It has been mostly straightforward on the cpp side, but i have been stuck with qml and its plugins for a long time.
The project uses static linking, i am building for Windows 11 with CMake, and i have already updated the plugins, where it was appropriate. Here are the Q_IMPORT_PLUGIN-s i use for context:Q_IMPORT_PLUGIN(QtQuick2Plugin) Q_IMPORT_PLUGIN(QtQmlMetaPlugin) Q_IMPORT_PLUGIN(QtQmlPlugin) Q_IMPORT_PLUGIN(QtQmlWorkerScriptPlugin) Q_IMPORT_PLUGIN(QtQmlXmlListModelPlugin) Q_IMPORT_PLUGIN(QtGraphicalEffectsPlugin) Q_IMPORT_PLUGIN(QtGraphicalEffectsPrivatePlugin) Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin) Q_IMPORT_PLUGIN(QtQuickControls2Plugin) Q_IMPORT_PLUGIN(QtQuickControls2WindowsStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2BasicStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2BasicStyleImplPlugin) Q_IMPORT_PLUGIN(QtQuickControls2ImplPlugin) Q_IMPORT_PLUGIN(QtQuickControls2FusionStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2FusionStyleImplPlugin) Q_IMPORT_PLUGIN(QtQuickDialogsPlugin) Q_IMPORT_PLUGIN(QtQuickControls2UniversalStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2UniversalStyleImplPlugin) Q_IMPORT_PLUGIN(QtQuickTemplates2Plugin) Q_IMPORT_PLUGIN(QGifPlugin) Q_IMPORT_PLUGIN(QJpegPlugin)
The project does build, and it starts, but it instantly throws an error:
Warning: qrc:/qml/MainBar.qml:36:2: Type Button unavailable Button{ ^ (qrc:/qml/MainBar.qml:36, ) Warning: qrc:/qt-project.org/imports/QtQuick/Controls/Windows/Button.qml: No such file or directory (qrc:/qt-project.org/imports/QtQuick/Controls/Windows/Button.qml:-1, )
I turned on QML_IMPORT_TRACE, to try figure things out. What i found is cpp implementations get resolved fine (So for example Item gets resolved as QQuickItem), while qml implementations are resolved, but are missing when referenced. It also seems like qml tries to resolve plugins dynamically, and fails, but i am unsure if that's a problem.
I will include parts of the debug, because the entire output is about 1500 lines.
Example of missing plugins:
Debug: importExtension: qrc:/qml/MainWindow.qml loaded ":/qt-project.org/imports/QtQuick/qmldir" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:963, class QTypeRevision __thiscall QQmlImports::importExtension(const class QString &,class QTypeRevision,class QQmlImportDatabase *,const class QQmlTypeLoaderQmldirContent *,class QList<class QQmlError> *)) Debug: resolvePlugin Could not resolve dynamic plugin with base name "qtquick2plugin" in ":/qt-project.org/imports/QtQuick" file does not exist (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlpluginimporter.cpp:454, class QString __thiscall QQmlPluginImporter::resolvePlugin(const class QString &,const class QString &)) Debug: loading dependent import "QtQml" version 2.12 as "" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmltypeloader.cpp:800, bool __thiscall QQmlTypeLoader::Blob::loadDependentImports(const class QList<struct QQmlDirParser::Import> &,const class QString &,class QTypeRevision,unsigned short,class QFlags<enum QQmlImports::ImportFlag>,class QList<class QQmlError> *)) Debug: addLibraryImport: qrc:/qml/MainWindow.qml "QtQml" version ' 2.12 ' as "" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:1206, class QTypeRevision __thiscall QQmlImports::addLibraryImport(class QQmlImportDatabase *,const class QString &,const class QString &,class QTypeRevision,const class QString &,const class QString &,class QFlags<enum QQmlImports::ImportFlag>,unsigned short,class QList<class QQmlError> *)) Debug: importExtension: qrc:/qml/MainWindow.qml loaded ":/qt-project.org/imports/QtQml/qmldir" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:963, class QTypeRevision __thiscall QQmlImports::importExtension(const class QString &,class QTypeRevision,class QQmlImportDatabase *,const class QQmlTypeLoaderQmldirContent *,class QList<class QQmlError> *)) Debug: resolvePlugin Could not resolve dynamic plugin with base name "qmlmetaplugin" in ":/qt-project.org/imports/QtQml" file does not exist (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlpluginimporter.cpp:454, class QString __thiscall QQmlPluginImporter::resolvePlugin(const class QString &,const class QString &))
Example of button being resolved:
Debug: resolveType: qrc:/qml/StyledButton.qml "Button" => "" QUrl("qrc:/qt-project.org/imports/QtQuick/Controls/Windows/Button.qml") TYPE/URL (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:479, bool __thiscall QQmlImports::resolveType(const class QHashedStringRef &,class QQmlType *,class QTypeRevision *,class QQmlImportNamespace **,class QList<class QQmlError> *,enum QQmlType::RegistrationType,bool *) const)
I tried everything i could think of. I added extra plugins, i tried rebuilding from zero, clearing cache. I also tried changing the CMake, but it seems not to be the problem, as if it would be the problem, i shouldn't even be able to build the project. For example if some plugins are not added in CMake i get a linker error with the Q_IMPORT_PLUGIN statement.
This project also built fine in Qt 5 with these methods, and i can't find what changed, that could cause these problems.
-
I've been porting a project from Qt 5.12 to 6.5. It has been mostly straightforward on the cpp side, but i have been stuck with qml and its plugins for a long time.
The project uses static linking, i am building for Windows 11 with CMake, and i have already updated the plugins, where it was appropriate. Here are the Q_IMPORT_PLUGIN-s i use for context:Q_IMPORT_PLUGIN(QtQuick2Plugin) Q_IMPORT_PLUGIN(QtQmlMetaPlugin) Q_IMPORT_PLUGIN(QtQmlPlugin) Q_IMPORT_PLUGIN(QtQmlWorkerScriptPlugin) Q_IMPORT_PLUGIN(QtQmlXmlListModelPlugin) Q_IMPORT_PLUGIN(QtGraphicalEffectsPlugin) Q_IMPORT_PLUGIN(QtGraphicalEffectsPrivatePlugin) Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin) Q_IMPORT_PLUGIN(QtQuickControls2Plugin) Q_IMPORT_PLUGIN(QtQuickControls2WindowsStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2BasicStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2BasicStyleImplPlugin) Q_IMPORT_PLUGIN(QtQuickControls2ImplPlugin) Q_IMPORT_PLUGIN(QtQuickControls2FusionStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2FusionStyleImplPlugin) Q_IMPORT_PLUGIN(QtQuickDialogsPlugin) Q_IMPORT_PLUGIN(QtQuickControls2UniversalStylePlugin) Q_IMPORT_PLUGIN(QtQuickControls2UniversalStyleImplPlugin) Q_IMPORT_PLUGIN(QtQuickTemplates2Plugin) Q_IMPORT_PLUGIN(QGifPlugin) Q_IMPORT_PLUGIN(QJpegPlugin)
The project does build, and it starts, but it instantly throws an error:
Warning: qrc:/qml/MainBar.qml:36:2: Type Button unavailable Button{ ^ (qrc:/qml/MainBar.qml:36, ) Warning: qrc:/qt-project.org/imports/QtQuick/Controls/Windows/Button.qml: No such file or directory (qrc:/qt-project.org/imports/QtQuick/Controls/Windows/Button.qml:-1, )
I turned on QML_IMPORT_TRACE, to try figure things out. What i found is cpp implementations get resolved fine (So for example Item gets resolved as QQuickItem), while qml implementations are resolved, but are missing when referenced. It also seems like qml tries to resolve plugins dynamically, and fails, but i am unsure if that's a problem.
I will include parts of the debug, because the entire output is about 1500 lines.
Example of missing plugins:
Debug: importExtension: qrc:/qml/MainWindow.qml loaded ":/qt-project.org/imports/QtQuick/qmldir" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:963, class QTypeRevision __thiscall QQmlImports::importExtension(const class QString &,class QTypeRevision,class QQmlImportDatabase *,const class QQmlTypeLoaderQmldirContent *,class QList<class QQmlError> *)) Debug: resolvePlugin Could not resolve dynamic plugin with base name "qtquick2plugin" in ":/qt-project.org/imports/QtQuick" file does not exist (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlpluginimporter.cpp:454, class QString __thiscall QQmlPluginImporter::resolvePlugin(const class QString &,const class QString &)) Debug: loading dependent import "QtQml" version 2.12 as "" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmltypeloader.cpp:800, bool __thiscall QQmlTypeLoader::Blob::loadDependentImports(const class QList<struct QQmlDirParser::Import> &,const class QString &,class QTypeRevision,unsigned short,class QFlags<enum QQmlImports::ImportFlag>,class QList<class QQmlError> *)) Debug: addLibraryImport: qrc:/qml/MainWindow.qml "QtQml" version ' 2.12 ' as "" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:1206, class QTypeRevision __thiscall QQmlImports::addLibraryImport(class QQmlImportDatabase *,const class QString &,const class QString &,class QTypeRevision,const class QString &,const class QString &,class QFlags<enum QQmlImports::ImportFlag>,unsigned short,class QList<class QQmlError> *)) Debug: importExtension: qrc:/qml/MainWindow.qml loaded ":/qt-project.org/imports/QtQml/qmldir" (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:963, class QTypeRevision __thiscall QQmlImports::importExtension(const class QString &,class QTypeRevision,class QQmlImportDatabase *,const class QQmlTypeLoaderQmldirContent *,class QList<class QQmlError> *)) Debug: resolvePlugin Could not resolve dynamic plugin with base name "qmlmetaplugin" in ":/qt-project.org/imports/QtQml" file does not exist (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlpluginimporter.cpp:454, class QString __thiscall QQmlPluginImporter::resolvePlugin(const class QString &,const class QString &))
Example of button being resolved:
Debug: resolveType: qrc:/qml/StyledButton.qml "Button" => "" QUrl("qrc:/qt-project.org/imports/QtQuick/Controls/Windows/Button.qml") TYPE/URL (C:\Qt\qt_6.5.3\qtdeclarative\src\qml\qml\qqmlimport.cpp:479, bool __thiscall QQmlImports::resolveType(const class QHashedStringRef &,class QQmlType *,class QTypeRevision *,class QQmlImportNamespace **,class QList<class QQmlError> *,enum QQmlType::RegistrationType,bool *) const)
I tried everything i could think of. I added extra plugins, i tried rebuilding from zero, clearing cache. I also tried changing the CMake, but it seems not to be the problem, as if it would be the problem, i shouldn't even be able to build the project. For example if some plugins are not added in CMake i get a linker error with the Q_IMPORT_PLUGIN statement.
This project also built fine in Qt 5 with these methods, and i can't find what changed, that could cause these problems.
@TekTek2000 you need to add this to your cmake file:
qt_import_qml_plugins(${PROJECT_NAME})
Repeat for every executable and library you create.
-
@TekTek2000 you need to add this to your cmake file:
qt_import_qml_plugins(${PROJECT_NAME})
Repeat for every executable and library you create.
@sierdzio This actually worked, thank you.
-
-
@sierdzio This actually worked, thank you.
@TekTek2000 as it should :-) It is the official, documented method for this: https://doc.qt.io/qt-6/qt-import-qml-plugins.html