Automatically import plugins in all applications with static Qt
Since all gui applications already need some QPA plugin added, we might as well add the default plugin and generate the code to import the plugins automatically. User can opt out from the automation by removing relevant items from CONFIG variable: link_qpa_plugin or import_plugins. Task-number: QTBUG-28131 Change-Id: Ic171c363464c099143374d3e39bcc28f6edf73d2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>bb10
parent
1433523960
commit
d4d2e4b39d
|
|
@ -1,2 +1,5 @@
|
|||
load(exclusive_builds)
|
||||
CONFIG = lex yacc warn_on debug exceptions testcase_targets depend_includepath $$CONFIG
|
||||
CONFIG = \
|
||||
lex yacc warn_on debug exceptions depend_includepath \
|
||||
testcase_targets import_plugins import_qpa_plugin \
|
||||
$$CONFIG
|
||||
|
|
|
|||
|
|
@ -35,9 +35,11 @@ QT_PLUGIN_VERIFY = DEPLOYMENT_PLUGIN
|
|||
contains(QT_CONFIG, static) {
|
||||
QT_PLUGIN_VERIFY += QTPLUGIN
|
||||
contains(TEMPLATE, .*app) {
|
||||
contains(QT, gui) {
|
||||
qpa_minimal_plugin: QTPLUGIN += qminimal
|
||||
qpa_default_plugin: QTPLUGIN += $$QT_DEFAULT_QPA_PLUGIN
|
||||
contains(QT, gui):import_qpa_plugin {
|
||||
qpa_minimal_plugin: \
|
||||
QTPLUGIN += qminimal
|
||||
else: \
|
||||
QTPLUGIN += $$QT_DEFAULT_QPA_PLUGIN
|
||||
}
|
||||
import_plugins:!isEmpty(QTPLUGIN) {
|
||||
IMPORT_FILE_CONT = \
|
||||
|
|
|
|||
|
|
@ -65,20 +65,3 @@ QStyle *MyStylePlugin::create(const QString &key)
|
|||
//! [2]
|
||||
QApplication::setStyle(QStyleFactory::create("MyStyle"));
|
||||
//! [2]
|
||||
|
||||
|
||||
//! [4]
|
||||
#include <QApplication>
|
||||
#include <QtPlugin>
|
||||
|
||||
Q_IMPORT_PLUGIN(qjpeg)
|
||||
Q_IMPORT_PLUGIN(qgif)
|
||||
Q_IMPORT_PLUGIN(qkrcodecs)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
...
|
||||
return app.exec();
|
||||
}
|
||||
//! [4]
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ CONFIG += release
|
|||
#! [3]
|
||||
|
||||
#! [4]
|
||||
CONFIG += qpa_default_plugin import_plugins
|
||||
CONFIG += qpa_minimal_plugin
|
||||
#! [4]
|
||||
|
||||
#! [5]
|
||||
|
|
@ -51,3 +51,11 @@ QTPLUGIN += qjpeg \
|
|||
qgif \
|
||||
qkrcodecs
|
||||
#! [5]
|
||||
|
||||
#! [6]
|
||||
CONFIG -= import_qpa_plugin
|
||||
#! [6]
|
||||
|
||||
#! [7]
|
||||
CONFIG -= import_plugins
|
||||
#! [7]
|
||||
|
|
|
|||
|
|
@ -266,18 +266,22 @@
|
|||
\row \li \c qsqltds \li SQL driver \li Sybase Adaptive Server (TDS)
|
||||
\endtable
|
||||
|
||||
To link statically against those plugins, you need to use the
|
||||
Q_IMPORT_PLUGIN() macro in your application and you need to add
|
||||
To link statically against those plugins, you need to add
|
||||
the required plugins to your build using \c QTPLUGIN.
|
||||
For example, in your \c main.cpp:
|
||||
|
||||
\snippet code/doc_src_plugins-howto.cpp 4
|
||||
Q_IMPORT_PLUGIN() macros are also needed in application code,
|
||||
but those are automatically generated by qmake and added to
|
||||
your application project.
|
||||
|
||||
In the \c .pro file for your application, you need the following
|
||||
entry:
|
||||
|
||||
\snippet code/doc_src_plugins-howto.pro 5
|
||||
|
||||
If you do not want all plugins added to QTPLUGIN to be automatically
|
||||
linked, remove \c import_plugins from the \c CONFIG variable:
|
||||
|
||||
\snippet code/doc_src_plugins-howto.pro 7
|
||||
|
||||
It is also possible to create your own static plugins, by
|
||||
following these steps:
|
||||
|
||||
|
|
@ -296,15 +300,16 @@
|
|||
to make sure that the \c{QT_STATICPLUGIN} preprocessor macro is
|
||||
defined.
|
||||
|
||||
Qt platform adaptation plugins are not automatically linked in static
|
||||
builds. To add default QPA plugin to \c QTPLUGIN variable and automatically
|
||||
generate Q_IMPORT_PLUGIN statements for your application, add the following
|
||||
The default Qt platform adaptation plugin is automatically added to QTPLUGIN
|
||||
in static builds. If you want to add the minimal plugin instead, add \c qpa_minimal_plugin
|
||||
to \c CONFIG:
|
||||
|
||||
\snippet code/doc_src_plugins-howto.pro 4
|
||||
|
||||
If the minimal QPA plugin is required, use \c qpa_minimal_plugin instead of
|
||||
\c qpa_default_plugin.
|
||||
If you want neither the default nor the minimal QPA plugin to be linked automatically,
|
||||
remove \c import_qpa_plugin from \c CONFIG:
|
||||
|
||||
\snippet code/doc_src_plugins-howto.pro 6
|
||||
|
||||
\section1 Deploying and Debugging Plugins
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue