Qt and Visual Studio. Tray icon disappearance - c++

I use Qt in Visual Studio and I needed to set a tray icon in the application.
I use the next code:
QSystemTrayIcon trayIcon = new QSystemTrayIcon(this);
QIcon trayImage(":/Res/myIcon.ico");
trayIcon->setIcon(trayImage);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->show();
My qrc file:
<RCC>
<qresource prefix="/">
<file>Res/myIcon.ico</file>
</qresource>
</RCC>
And it worked. But when I moved my application to another computer it failed with the error "This application failed to start because it could not find or load the Qt platform plugin 'windows'.". I solved it by creating the directory "platforms" in the directory with execution files and putting qwindows.dll in it. But after that the icon disappeared. I see only blank square in the tray. I can use tray icon actions but my image doesn't display.
Thanks for any idea why it happens.

When deploying Qt application to other machines, you'll also need to deploy plugins for the needed image formats. In your case you must create the imageformats directory and copy the qico.dll plugin (which can be found in the Qt SDK directory).
Nonetheless, I recommend using the PNG format for your tray icon in view of its better portability.

I read description of QIcon class, where you can find link to supported formats QImageReader::supportedImageFormats() and there is no .ico format.
I'm not sure, but probably it can be source of your problem. Try to change icon format to another one.

you should use one of the supported format of Image in qt. for example if you use .png format, it will shows.

Related

Select an png icon for Qt application executable

I am working with Qt to create a front-end for my application. Now I wanted to set an customized ICON for my application executable. I am using Qt 6.4. Already I create an resource file which it has .qrc format. Then I added my icon to that resource file. Now I wanted to know how can I set that icon file as executable icon. Is that possible somebody explain how can I set an customized icon for my application? Also I wanted to know how can I modify CMake to instruct compiler which executable should run with administrator privilege. Thank you.
Solution depends on your platform (Windows, mac, Linux) as well as your configuration tool (CMake, qmake).
Have a look at Qt documentation: https://doc.qt.io/qt-6/appicon.html. It tells what to do.
To achieve that, in my side, I'm doing 2 things :
1.
QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/img/AppIcon.png"));
Create a resource.rc file with this content (have to possess a .ico version of the image)
IDI_ICON1 ICON DISCARDABLE "img/AppIcon.ico"
and declare in .pro
RC_FILE += \
resource.rc

How to change icon in .exe (App Wxwidgets with C++)

I have build an app with Code::Block, C++ and wxWidgets. I have changed icon for frame successfully, but icon of .exe file is still there default.
how to change icon of .exe file?
Thanks
Edit .rc file (i.e. resource.rc) and set your icon where you find aaaa ICON.

seticon is not working

I have develop a file browser in Qt/C++. I'm displaying the files and folders but I want to add an icons if it's a files or a folders.
I have used :
item->setIcon(0,*(new QIcon(":images/file.jpg")));
But nothing is displayed. I have add the file into the project, it appears in the "Other Files"/"images" folder of the project.
Do I need to declare the file in other location and how ?
Thanks
Are you developing with Qt Creator?
I think there are 2 approachs to solve this problem:
1) Try to load the file as new QIcon("qrc:/images/file.jpg"); Maybe there is a problem loading from the resources.
2) Try to change the jpg to a png file as vahancho said (jpeg library must be attached to the project to support jpeg in qt) - Jpeg qt plugin
Regards.

How to set/change the application icon?

I'm Confused about set the application icon.
I have seen many explanations about set the application icon, but I'm still not understand.
Please I want a simple explanation, but step by step to understand it
What I have done:
I have created a Qt resource file(.qrc).
Then, I have added a prefix, then I have added the Icon file.
Then, from design mode and from property block I have changed the a property called windowIcon.
Then I have selected the Icon which I added before in the .qrc file.
Notice: I'm use Qt5.3 and windows 7.
Now, Please what is the right steps to set the application icon ?
You have done the right thing to set the main window icon. Just setting windowIcon property in the designer will set an icon for the application window.
For setting an icon to the application executable file there is an automated process In Qt 5.
You can just add the following to the .pro file:
win32: RC_ICONS = myIcon.ico
Also store the .ico file in your application's source code directory.
Note that this is only for Windows. There are other ways to set application icon in Linux and Mac.

MFC logo in a MFC application

I have an MFC application. When the application is launched, I see it is represented on the taskbar using the MFC logo. Also, the application Window Menu Bar has the MFC icon.
How can I replace these with custom made logos?
The icons are in the .ico file that is part of your project. Usually in the /res directory. You can edit them or replace them with files you generate.
The icon file is stored with your project files.
Go to <Projects Folder>\SOLUTIONNAME\PROJECTNAME\res. When you locate this folder, there should be a PROJECTNAME.ico file. rename the ico file you created to PROJECTNAME.ico. Next time you build your project, the MFC icon should be replaced with your custom icon.
I recommend going to this site mostly because it does not require any registration and its 100% free.
You can then fine a suitable icon for your program bu searching keywords.
Then select the .ICO type and download.
Copy the .ico file to your “res” folder.
Then delete the .ico file and rename the downloaded file to .ico.