Reading .desktop files
-
Hello! I am exploring how to use Qt by creating an application launcher type thing. One thing I need to do is read .desktop files to present application names, and call their exec lines. I come from a GTK background where objects for this are provided by GLib: GDesktopAppInfo
Does something similar exist in Qt? I tried searching for related terms in the documentation center and didn't see anything.
Right now I'm using my own class and parsing the files by hand, but I'm not sure if this works with the localized keys in desktop files:
Application::Application(QString desktopId, QSettings * appInfo) : desktopId(std::move(desktopId)) { appInfo->beginGroup("Desktop Entry"); this->name = appInfo->value("Name").toString(); this->description = appInfo->value("Description").toString(); this->exec = appInfo->value("Exec").toString(); this->categories = appInfo->value("Categories").toString(); this->genericName = appInfo->value("GenericName").toString(); this->onlyShowIn = appInfo->value("OnlyShowIn").toString().split(";"); this->notShowIn = appInfo->value("NotShowIn").toString().split(";"); this->noDisplay = appInfo->value("NoDisplay").toBool(); this->prefersDefaultGpu = !appInfo->value("PrefersNonDefaultGPU").toBool(); this->dbusActivatable = appInfo->value("DBusActivatable").toBool(); appInfo->endGroup(); }
-
Hi and welcome to devnet,
You might want to check if the KDE APIs contains something for it.
-
@EbonJaeger Since Qt apps can be launched from command line on Linux, not from a launcher, I have not noticed Qt has this feature. I create it in my cmake file. But you may try to link GLib to your app(often it is linked) and use GLib: GDesktopAppInfo in your Qt app.
-
Hi and welcome to devnet,
You might want to check if the KDE APIs contains something for it.
-
@SGaist Thanks for pointing me in the right direction; it looks like what I am after is KDesktopFile.
-
E EbonJaeger has marked this topic as solved on