diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 01:27:27 +0100 |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 01:27:39 +0100 |
commit | 12f221410fbe41d0b2efda4cd3289dfcf9044aa8 (patch) | |
tree | 897cf6bfb1814b0935982ff5975a6cbfb48d6d9e /src/printsupport/kernel/qplatformprintplugin.cpp | |
parent | 3d19422ef16a230bb11dbbfe4a8cc9667f39bf15 (diff) | |
parent | 6c612c933803ef57ea45e907d0181b40659148ac (diff) |
Merge remote-tracking branch 'origin/master' into api_changes
Change-Id: I89dc2e193bd01624c1fb50484610d516e39b1538
Diffstat (limited to 'src/printsupport/kernel/qplatformprintplugin.cpp')
-rw-r--r-- | src/printsupport/kernel/qplatformprintplugin.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp index 409de3eb4a..2c87fcc5e6 100644 --- a/src/printsupport/kernel/qplatformprintplugin.cpp +++ b/src/printsupport/kernel/qplatformprintplugin.cpp @@ -58,15 +58,27 @@ QPlatformPrinterSupportPlugin::~QPlatformPrinterSupportPlugin() { } +/*! + \internal + + Returns a lazily-initialized singleton. Ownership is granted to the + QPlatformPrinterSupportPlugin, which is never unloaded or destroyed until + application exit, i.e. you can expect this pointer to always be valid and + multiple calls to this function will always return the same pointer. +*/ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get() { - QStringList k = loader()->keys(); - if (k.isEmpty()) - return 0; - QPlatformPrinterSupportPlugin *plugin = qobject_cast<QPlatformPrinterSupportPlugin *>(loader()->instance(k.first())); - if (!plugin) - return 0; - return plugin->create(k.first()); + static QPlatformPrinterSupport *singleton = 0; + if (!singleton) { + QStringList k = loader()->keys(); + if (k.isEmpty()) + return 0; + QPlatformPrinterSupportPlugin *plugin = qobject_cast<QPlatformPrinterSupportPlugin *>(loader()->instance(k.first())); + if (!plugin) + return 0; + singleton = plugin->create(k.first()); + } + return singleton; } QT_END_NAMESPACE |