[Development] QLibrary and QCoreApplication::libraryPaths()

David Faure david.faure at kdab.com
Sat Sep 8 03:59:57 CEST 2012


QCoreApplication::libraryPaths() is documented as the search paths for loading 
plugins, but it turns out that only plugins for Qt itself are looked up there 
[by the internal QFactoryLoader class].

Application plugins are not searched in these paths. I expected them to be :)

Can I add (in Qt-5.1, I guess) a 
static QString findLibrary(const QString& libname)
in QLibrary?

The alternative would be to change what load() does, in case of relative 
paths, but I think we'd rather keep its current behavior (load the plugin 
relative to the current directory, like QFile would do), for speed reasons.

QLibrary::findLibrary would allow to look up a library in the paths before 
calling the constructor. It would have to share the code that tries various 
suffixes though.... This is why it should be in Qt: to encapsulate the OS 
differences, this isn't just about a foreach(path, libraryPaths)+QFile::exists.


The goal is to be able to write this in a qt-based library:
    QLibrary lib(QLatin1String("kf5/ktranscript"));
and it should find PREFIX/lib64/plugins/kf5/ktranscript.so
(.dll on windows)
after ensuring QT_PLUGIN_PATH contains PREFIX/lib64/plugins
(when PREFIX is different from Qt's).

Thoughts?

-- 
David Faure | david.faure at kdab.com | Managing Director KDAB France
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions




More information about the Development mailing list