API trap in KService::property()
Open, Needs TriagePublic

Description

KService has property(QString, QMetaType::Type) and property(QString), the latter inherited from KSycocaEntry.

property(QString) effectively does property(QString, QMetaType::Unknown). In KF5 this then resolved the actual type via the servicetype file. In KF6 that doesn't happen any more. There is a hardcoded list of properties and their types (https://invent.kde.org/frameworks/kservice/-/blob/master/src/services/kservice.cpp#L432), but for any other property this doesn't work. Explicitly stating the type makes it work.

That's very not obvious. There's a warning printed about the type not being found, but only on debug level and thus off by default.

I see some options:

  • Crank up the output to warning level
  • Make passing a type parameter mandatory (i.e. remove the second overload). Needs fixing a bunch of consumers, but seems manageable
  • 'service->property("Foo", QMetaType::QStringList).toStringList()' is a bit of a mouthful. Can/should we make it something like 'service->property<QStringList>("Foo")'?

'service->property("Foo", QMetaType::QStringList).toStringList()' is a bit of a mouthful. Can/should we make it something like 'service->property<QStringList>("Foo")'?

https://invent.kde.org/frameworks/kservice/-/merge_requests/155 does this

nicolasfella moved this task from Backlog to In Progress on the KF6 board.Nov 7 2023, 11:26 PM
nicolasfella moved this task from In Progress to Done on the KF6 board.