0

I was trying to create a style plugin for my project, the plugin seems being loaded, but why QStyleFactory::keys() didn't return my key? By setting QT_DEBUG_PLUGINS to 1, I got following message :

Found metadata in lib .../styles/libstyles.so, metadata=
{
    "IID": "this.is.my.style",
    "MetaData": {
        "Keys": [
            "mystyle"
        ]
    },
    "className": "MyStylePlugin",
    "debug": true,
    "version": 329986
}

in my main():

QApplication app(argc, argv);
QApplication::setStyle(QStyleFactory::create("mystyle"));
qDebug() << QStyleFactory::keys();

The last qDebug statement prints:

Got keys from plugin meta data ()
("Windows", "Fusion") <= Shouldn't "mystyle" also show up here?
n.x.
  • 31
  • 4

1 Answers1

3

That's because your IID should be ""org.qt-project.Qt.QStyleFactoryInterface" not "this.is.my.style". If you change the IID, the plugin is not recognize as a style plugin by Qt.

Here is an extract of Qt code where the keys are detected:

QString iid = library->metaData.value(QLatin1String("IID")).toString();
if (iid == QLatin1String(d->iid.constData(), d->iid.size())) {
    QJsonObject object = library->metaData.value(QLatin1String("MetaData")).toObject();
    metaDataOk = true;
    QJsonArray k = object.value(QLatin1String("Keys")).toArray();
    for (int i = 0; i < k.size(); ++i)
        keys += d->cs ? k.at(i).toString() : k.at(i).toString().toLower();
}
if (qt_debug_component())
    qDebug() << "Got keys from plugin meta data" << keys;

You can see that on the 2nd line if the IID from you plugin does not match the expected IID (d->iid), the code will not bother to try to read the MetaData.

Benjamin T
  • 8,120
  • 20
  • 37
  • Thanks Benjamin! You are right, after modifying IID, it just works! I thought IID could be anything, but didn't know plugin loader would use it to determine whether to load it. Sorry I am not able to increase displayed score because my reputation is too low for now. – n.x. Nov 02 '17 at 20:02