Qml with static build
-
Hello. I've seen a lot of topics about this problem but no one of them solved my problem. So when i creating new QtQuick application with QtQuick 2.4 i have an error: Project ERROR: Unknown module(s) in QT: quick qml. If i use QtQuick 1.1 i have: Project ERROR: Unknown module(s) in QT: declarative. Is there any way to creat QtQuick applications with static libraries using Qt 5.4? Thanks.
-
@Dmitriy said:
s there any way to creat QtQuick applications with static libraries using Qt 5.4? Thanks.
Hi Dmitriy,
What is the specific situation you are having now? QML is interpreted, normally qml files are read directly from local files or embedded into .qrc files. That way, you either:
- Put common QML files into a folder, which is used directly or added into different .qrc files of Qt applications.
Or - From C++ codes being built into libraries, we could create QML plugins from that and use them in QML code.
Refer here for more details:
http://doc.qt.io/qt-5/qtqml-modules-topic.htmlBy the way, remember to specify the modules being used in project file:
http://doc.qt.io/qt-5/qmake-variable-reference.html#qt - Put common QML files into a folder, which is used directly or added into different .qrc files of Qt applications.
-
There is a way to get it working that's not too painful. That this scenario is so poorly documented is a major failing of Qt for me, though. On Windows, an application statically linked with Qt provides perhaps the smallest distribution size, and so can be desirable in a lot of cases. The documentation for the whole process (building Qt statically, building your application, and then deploying it) should be front and centre with a flashing orange light on it, but instead you have to dig, and dig. It's desperately poor.
Anyway, there may be a more efficient way to do it, but for a working solution, here's what we do (an approach cobbled together from scraps of third-party comments lurking in dark corners of the web):
-
Add your QML files to your project using the Resource system
-
In the same directory as your .pro project file, create a file called QmlImports.qml and add it to your project (normally, not embedded as a resource). Its contents should be something like this, where you import the QtQuick modules you need:
import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 import QtQuick.Controls.Styles 1.2 /* QmlImports.qml Declaration of QML Imports required by project. This is necessary if we want to keep qml files in a folder separate from .pro file because of the way qmlimportscanner works. If these imports are not declared, qmake will not recognize them, and QtQuick will not be packaged with statically built apps and imported at runtime. This must be kept in the same directory as your .pro file */ QtObject {}
-
Run qmake, then build your application, linking to your static Qt build
-
In the folder where your output .exe lives, create a folder called qml and copy into it the following folders from the qml folder of your static Qt build:
a) QtQuick.2 - the files in there that you need are plugins.qmltypes, qmldir, and qtquick2plugin.dll
b) QtQuick - start by copying this whole folder over; later you can trim away the files you don't need. What needs to be in there is the folder for each QML module, containing its QML files and the DLL. -
Finally, in the folder where your .exe lives, create a file called qt.conf, containing this:
[Paths] Plugins=qml
Once you've packaged up those files with your distribution, it should run on PCs that have no Qt libraries installed.
Cheers,
Garry
-
-
I raised an issue in the Qt Bug Tracker, see QTBUG-72810: Static build package in Qt installer. You may want to vote up that issue.
-
There is a way to get it working that's not too painful. That this scenario is so poorly documented is a major failing of Qt for me, though. On Windows, an application statically linked with Qt provides perhaps the smallest distribution size, and so can be desirable in a lot of cases. The documentation for the whole process (building Qt statically, building your application, and then deploying it) should be front and centre with a flashing orange light on it, but instead you have to dig, and dig. It's desperately poor.
Anyway, there may be a more efficient way to do it, but for a working solution, here's what we do (an approach cobbled together from scraps of third-party comments lurking in dark corners of the web):
-
Add your QML files to your project using the Resource system
-
In the same directory as your .pro project file, create a file called QmlImports.qml and add it to your project (normally, not embedded as a resource). Its contents should be something like this, where you import the QtQuick modules you need:
import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 import QtQuick.Controls.Styles 1.2 /* QmlImports.qml Declaration of QML Imports required by project. This is necessary if we want to keep qml files in a folder separate from .pro file because of the way qmlimportscanner works. If these imports are not declared, qmake will not recognize them, and QtQuick will not be packaged with statically built apps and imported at runtime. This must be kept in the same directory as your .pro file */ QtObject {}
-
Run qmake, then build your application, linking to your static Qt build
-
In the folder where your output .exe lives, create a folder called qml and copy into it the following folders from the qml folder of your static Qt build:
a) QtQuick.2 - the files in there that you need are plugins.qmltypes, qmldir, and qtquick2plugin.dll
b) QtQuick - start by copying this whole folder over; later you can trim away the files you don't need. What needs to be in there is the folder for each QML module, containing its QML files and the DLL. -
Finally, in the folder where your .exe lives, create a file called qt.conf, containing this:
[Paths] Plugins=qml
Once you've packaged up those files with your distribution, it should run on PCs that have no Qt libraries installed.
Cheers,
Garry
@monomix Just 4yrs old and this is what I needed! In my case, I'm building for iOS under LGPL and using a static library as a means of allowing users to build my app without giving them the source code. I couldn't understand why QtQuick wouldn't load; thanks!
-