slevin_by
slevin_by

Reputation: 15

Qt and Visual Studio. Tray icon disappearance

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.

Upvotes: 1

Views: 432

Answers (3)

Faezeh
Faezeh

Reputation: 171

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

Upvotes: 0

kefir500
kefir500

Reputation: 4404

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.

Upvotes: 3

t3ft3l--i
t3ft3l--i

Reputation: 1412

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.

Upvotes: 1

Related Questions