HowTo set Icon to Qt Application, created with Qt Visual Studio Add-in?
Asked Answered
P

5

7

Here is what I have:

  • Visual Studio 2008 (on 32-bit Windows XP)
  • Qt libraries 4.6.2 for Windows (VS 2008, 194 MB)
  • Visual Studio Add-in (44 MB)

After I installed all the software, I created simple Qt Application project, with Visual Studio: menu File | New | Project... and Qt4 Projects | Qt Application.

Build it, and here is the question: how to set application icon to my compiled exe file? I need to see specified ICO in explorer!


Old method with MyProject.pro not interested!!!

  1. Create a .ico file with both 16x16 and 32x32-pixel versions of the icon (you can do this in Visual Studio).

  2. Create a .rc file containing the following text:

    IDI_ICON1 ICON DISCARDABLE "myIcon.ico"

  3. Add the following to your .pro file

    RC_FILE = myFile.rc

  4. Run qmake.

Thanks.

Paediatrics answered 1/6, 2010 at 11:18 Comment(0)
P
5

Totally, I have found the correct solution, here it is:

Preamble: You need Visual Studio Add-in already installed!

  1. Open Visual Studio (or Visual C++)

  2. Create new project from menu: File | New | Project... and select project type as Qt4 Projects and for example Qt Application from templates.

  3. When the first dialog window will be shown, just click Next > button twice.

  4. And finally in Generated Class tap the Add default application icon (Windows only) checkbox.

    alt text http://www.freeimagehosting.net/uploads/7f87801fb9.png

  5. To finish process, just press Finish.

Project will create a default icon, with name {your_project_name}.ico. Replace it and have fun!

Paediatrics answered 8/6, 2010 at 7:36 Comment(1)
The hosted image no longer exists. The image should have been in-lined and hosted on SO. It has been a while, but can you fix it?Jackass
A
6

This is what worked for me [VS2010, Qt Add-in 1.1.8], for an existing project:

As in the docs at http://doc.qt.io/qt-4.8/appicon.html :

  • Add icon file (myappico.ico) to source dir

  • Create myapp.rc file with the line

    IDI_ICON1 ICON DISCARDABLE "myappico.ico"

[Of course, the file names are free to choose, as long as they are consistent]

  • Right-click project, choose Add | Existing item... and pick the RC file

  • Rebuild

Arenicolous answered 9/5, 2011 at 8:19 Comment(0)
P
5

Totally, I have found the correct solution, here it is:

Preamble: You need Visual Studio Add-in already installed!

  1. Open Visual Studio (or Visual C++)

  2. Create new project from menu: File | New | Project... and select project type as Qt4 Projects and for example Qt Application from templates.

  3. When the first dialog window will be shown, just click Next > button twice.

  4. And finally in Generated Class tap the Add default application icon (Windows only) checkbox.

    alt text http://www.freeimagehosting.net/uploads/7f87801fb9.png

  5. To finish process, just press Finish.

Project will create a default icon, with name {your_project_name}.ico. Replace it and have fun!

Paediatrics answered 8/6, 2010 at 7:36 Comment(1)
The hosted image no longer exists. The image should have been in-lined and hosted on SO. It has been a while, but can you fix it?Jackass
G
2

From official document, it says:
If you do not use qmake, the necessary steps are: first, run the rc program on the .rc file, then link your application with the resulting .res file.

I tryed several times, it should be done like below:
1. Add an ico resource file to your project;
2. rename the file "yourappico.ico";
3. rebuild your project to generate yourapp.res file;
4. link your application with the resulting .res file.
( Projects->Properties->Linker->Input->Assembly link resource )

Gathard answered 28/2, 2011 at 3:17 Comment(0)
R
2

You could also load it in manually. Following approach works for me:

#include <QtGui/QIcon>

QIcon icon("Resources/appicon.ico");
QMainWindow *window = new QMainWindow();
window->setWindowIcon(icon);
window->show();

Put your .ico file inside the Resources-Folder of your VS-Project.

(oops, did not fully read the question, but I just leave the answer it anyway... ^^)

Rybinsk answered 18/7, 2014 at 12:3 Comment(0)
A
-2

Right click you project on Solution Explorer and using the "Add" option include your icon in the project. It will include your icon and setup a rc file for you.

Abaddon answered 2/6, 2010 at 19:21 Comment(3)
No, your answer not a solution. It's like if some one ask "what is a cow?", other man answered: "Oh, it's like a cat, or like a dog, but big, or just fat"... I think you better to remove such an answer. It's not the best one, but thank you!Paediatrics
The icon shown in explorer is defined by the first icon resource in the solution. You need a resource file and it must be setup in some way - be it a .pro or by using the Solution Explorer context menu. I don't believe you can find a different answer. And, next time, be polite.Abaddon
As you can see from my question, I set bold one of the lines: Visual Studio Add-in (44 MB). If I created Qt Application project with that add-in, it doesn't generate, or even used pro-files. Every information it, if I'm not mistaken, store in MSVC solution file, but not in pro. So adding RC_FILE = myFile.rc in pro is impossible! I don't want be polite, when you stolen my Tumbleweed badge!!! :|Paediatrics

© 2022 - 2024 — McMap. All rights reserved.