Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading .desktop files
Forum Updated to NodeBB v4.3 + New Features

Reading .desktop files

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 615 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EbonJaegerE Offline
    EbonJaegerE Offline
    EbonJaeger
    wrote on last edited by
    #1

    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();
    }
    
    JoeCFDJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi and welcome to devnet,

      You might want to check if the KDE APIs contains something for it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      EbonJaegerE 1 Reply Last reply
      0
      • EbonJaegerE EbonJaeger

        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();
        }
        
        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #2

        @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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #3

          Hi and welcome to devnet,

          You might want to check if the KDE APIs contains something for it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          EbonJaegerE 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            You might want to check if the KDE APIs contains something for it.

            EbonJaegerE Offline
            EbonJaegerE Offline
            EbonJaeger
            wrote on last edited by
            #4

            @SGaist Thanks for pointing me in the right direction; it looks like what I am after is KDesktopFile.

            1 Reply Last reply
            1
            • EbonJaegerE EbonJaeger has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved