Solved The cost of plugin scans
-
Not knowing how your custom system is built I can't really point you to the best resources for that.
- By checking the Qt documentation (and possibly also what other projects like yocto do)
- Is there some qt.conf file in your system ?
Unless some customization is done, Qt will only scan the appropriate folders that are created when you install it.
That said, do you have custom plugins for your application ?
-
No, only one plugin (the platform plugin), which is shared among all Qt applications.
The point I am trying to make (and perhaps belongs in a bug report) is that opening and mapping all files, even in a known directory, is bad practice in general, but especially on an embedded system. There has to be a better way to let Qt know which are the plugins of interest (e.g., using a manifest file, or just a naming convention).--Elad
-
I understand your issue.
To the best of my knowledge there is none currently. If memory serves well the mapping is used to get the plugin metadata in order to load the ones requested.
From a deployment point of view, what I would do (and have done in the past) is to customize the cross-compiled version to use only what was needed and thus also deploy only what was required. This minimized the footprint of Qt as well as the application.
-
Hi, one other possibility is if you can build a static version of Qt and build your app with that. Then all plugins are placed together with your code in the same .exe/.elf file.
That executable file will be bigger, say around 20 - 40 MB, but no file mappings/scans are needed for the plugins :-) -
@hskoglund Sure, but I have many Qt apps (in fact a whole desktop system of Qt apps...). Some of these use QtWebkitWidgets, which is not a small library.
I can easily hack
QFactoryLoader()
to consider only files with a given name prefix/suffix. I posted here just to know if there is an existing way of avoiding the scan and if anyone else has noticed the problem.--Elad
-
And I assume you also have tried forcing/resetting the scan of plugins to a specific folder by using QCoreApplication::setLibraryPaths just before your QApplication constructor call?
-
Good idea, but it doesn't help.
int main(int argc, char *argv[]) { QCoreApplication::setLibraryPaths(QStringList() << "/system/lib/plugins"); QApplication app(argc, argv); qDebug() << app.libraryPaths();
produces
("/system/lib/qt", "/system/lib/plugins", "/system/opt/swmlogin")
The path from
QT_QPA_PLATFORM_PLUGIN_PATH
is still there but, more importantly, so is the path of the executable. The latter is mentioned in the documentation ofsetLibraryPaths()
as still being searched. Not to mention having to change the code of every application I use is not a viable solution.Anyway, I'll create a bug report at least to provide an option to suppress/restrict scanning.
--Elad
-
Hi, forgot one more option: create a qt.conf file next to your executable, with something like this inside:
[Paths] Prefix=/system/lib Plugins=/system/opt/swmlogin
i..e set Plugins to the path of your executable's folder, then Qt will look for the platforms subdirectory in that folder.
(I think Qt's factoryloader does a deduplication of the entries so that it will only scan the folder once)
And also no modification of source code needed :-) -
Hmm... qt.conf seems to have no effect, Strange.
By the way, it looks like Windows only scans for files with the suffix
.dll
and Android only scans for files starting withlibplugins_
. FromQFactoryLoader::update()
:QStringList plugins = QDir(path).entryList( #if defined(Q_OS_WIN) QStringList(QStringLiteral("*.dll")), #elif defined(Q_OS_ANDROID) QStringList(QLatin1String("libplugins_%1_*.so").arg(d->suffix)), #endif QDir::Files);
-
I rearranged things on the system:
- Dropped
QT_QPA_PLATFORM_PLUGIN_PATH
- Set
QT_PLUGIN_PATH
to/system/lib/qt/plugins
- Created a folder called
platforms
under the plugin path and moved the platform plugin there
Qt no longer maps any file other than the platform plugin, which is what I wanted from the start. I still don't understand the scan logic, but at least this problem is solved.
Thanks,
--Elad - Dropped