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. getting icon from external applications
Forum Updated to NodeBB v4.3 + New Features

getting icon from external applications

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 3.0k Views
  • 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.
  • M Offline
    M Offline
    mjzarrin
    wrote on 18 Jan 2016, 19:55 last edited by
    #1

    hello dear friends
    i prepare an uninstaller for windows. i need to get icon of every application beside program name in table widget.
    after some googling i write a test code for getting icons but it not worked and my computer not respond to any thing until i kill the process.
    this is my test code.

    void MainWindow::on_pushButton_clicked()
    {
        QFileInfo fin("C:/Program Files/CCleaner/CCleaner.exe");
        QTableWidgetItem *it = new QTableWidgetItem("Hello");
        QFileIconProvider qq;
        QIcon ic = qq.icon(fin);
        ui->tableWidget->insertRow(0);
        it->setIcon(ic);
        ui->tableWidget->setItem(0,0,it);
    }
    

    please help me what i must to do.
    thanks

    D 1 Reply Last reply 19 Jan 2016, 08:23
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 19 Jan 2016, 05:35 last edited by
      #2

      I don't think you can use C:/Program Files/CCleaner/CCleaner.exe directly to create QIcon as it is an executable containing an icon but not just an icon. You need to extract the icon from the executable. I don't know how to do that. I know there is at least one open source exe thumb-nailer for Linux, maybe you can find some inspiration there. And I'm quite sure there is some specification/documentation for the Windows binary format (exe format). And finally you could use an hex editor and open a simple exe with embedded icon to see how it is stored there.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 19 Jan 2016, 07:03 last edited by
        #3

        maybe this helps. I assume you need a Windows only solution?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • M mjzarrin
          18 Jan 2016, 19:55

          hello dear friends
          i prepare an uninstaller for windows. i need to get icon of every application beside program name in table widget.
          after some googling i write a test code for getting icons but it not worked and my computer not respond to any thing until i kill the process.
          this is my test code.

          void MainWindow::on_pushButton_clicked()
          {
              QFileInfo fin("C:/Program Files/CCleaner/CCleaner.exe");
              QTableWidgetItem *it = new QTableWidgetItem("Hello");
              QFileIconProvider qq;
              QIcon ic = qq.icon(fin);
              ui->tableWidget->insertRow(0);
              it->setIcon(ic);
              ui->tableWidget->setItem(0,0,it);
          }
          

          please help me what i must to do.
          thanks

          D Offline
          D Offline
          Devopia53
          wrote on 19 Jan 2016, 08:23 last edited by
          #4

          @mjzarrin

          Hi,

          The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes according to the Qt Docs.

          If you need only application's icon, following code:

              QFileInfo  fin("C:/Program Files/CCleaner/CCleaner.exe");
              QTableWidgetItem *it = new QTableWidgetItem("Hello");
              QFileSystemModel *model = new QFileSystemModel;
          
              model->setRootPath(fin.path());
          
              QIcon ic = model->fileIcon(model->index(fin.filePath()));
          
              ui->tableWidget->insertRow(0);
              it->setIcon(ic);
              ui->tableWidget->setItem(0, 0, it);
          
          

          or

          QFileInfo  fin("C:/Program Files/CCleaner/CCleaner.exe");
          QTableWidgetItem *it = new QTableWidgetItem("Hello");
          QFileSystemModel  *model = new QFileSystemModel;
          
          model->setRootPath(fin.path());
          
          QFileIconProvider   *qq = model->iconProvider();
          QIcon  ic = qq->icon(fin);
          
          ui->tableWidget->insertRow(0);
          it->setIcon(ic)
          ui->tableWidget->setItem(0, 0, it);
          
          1 Reply Last reply
          1
          • M Offline
            M Offline
            mjzarrin
            wrote on 19 Jan 2016, 10:22 last edited by
            #5

            Hello My Friends
            Thank you @jsulm .
            Thank you @raven-worx .
            and thank you @Devopia53 for the best and right solution. It work like a charm. It is what i need.
            thanks.

            1 Reply Last reply
            0

            1/5

            18 Jan 2016, 19:55

            • Login

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