PDA

View Full Version : Problem using System Tray Icon....



Bong.Da.City
29th August 2010, 14:19
Hi i am trying to make a System Tray Icon to be shown everytime i minimize my application......

if (isMinimized()) {
trayIcon->show();
enum MessageIcon { NoIcon, Information, Warning, Critical };
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(Information);
trayIcon->showMessage("titlos", "mplampla", icon, 10000);
emit minimized();}

So my problem is that the System Tray Icon is been shown the the top left of the computer and not at my trayicon.... What should i do?

squidge
29th August 2010, 20:02
Unlikely to be your problem, but still, I must ask why you declare your own enum rather than using the types built into QSystemTrayIcon ?

Also, you shouldn't depend on showMessage, as supportsMessages() may return false on some platforms.

wysota
29th August 2010, 20:10
show() doesn't cause the icon to appear, it only tells the system you want it to appear. If you showMessage() when the icon is invisible, it is likely the message gets wrong geometry because of invalid geometry of the tray icon.

Bong.Da.City
29th August 2010, 20:17
Ok so what should i put instead of the source code i gived you? I had replaced showMessage() with show() but i have an error (void value not ignored as it ought to be)

wysota
29th August 2010, 20:30
Ok so what should i put instead of the source code i gived you?
Hard to say as I don't know what you're trying to do but the easiest thing you can try is to call

QApplication::sendPostedEvents(trayIcon);
after calling show() on the tray icon object.

Bong.Da.City
29th August 2010, 20:49
I had found an example from here (http://cep.xor.aps.anl.gov/software/qt4-x11-4.2.2/desktop-systray.html).. But even this project is is working i cannot do that to my own... Any ideas?

Ps.. because you will spend a lot of time to make the project of the example i can give you just the exe file.. 5119

wysota
29th August 2010, 21:23
But even this project is is working i cannot do that to my own...
This project works because it doesn't show the message right after calling show() on the tray icon. Your does and thus it probably fails.

Bong.Da.City
29th August 2010, 21:47
Xmm i think that you are right... But the point of the system trayicon message is to be shown after the application is minimized...
i had putted just now sleep(1) bu now when you minimize the application it sleeps for 1 sec and then show the tray.icon and the message again on the top left..
Pff... What sould i do... ?

wysota
29th August 2010, 22:14
I have already told you what to do. Read post #5 in this thread again.

Bong.Da.City
29th August 2010, 22:30
It doesn't work.. look at the code.. is it what you mean?


if (isMinimized()) {
trayIcon->show();
QApplication::sendPostedEvents(trayIcon);
emit minimized();
enum MessageIcon { NoIcon, Information, Warning, Critical };
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(Information);
trayIcon->showMessage("titlos", "mplampla", icon, 10000);
}

Error: no matching function for call to ‘QCoreApplication::sendPostedEvents(QSystemT rayIcon*&)’

wysota
30th August 2010, 07:56
Error: no matching function for call to ‘QCoreApplication::sendPostedEvents(QSystemT rayIcon*&)’
Obviously the error message is correct. Look at the signature of sendPostedEvents() in the docs.

Bong.Da.City
30th August 2010, 10:28
if (isMinimized()) {
trayIcon->show();
QCoreApplication::sendPostedEvents(QSystemTrayIcon *&);
enum MessageIcon { NoIcon, Information, Warning, Critical };
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(Information);
trayIcon->showMessage("titlos", "mplampla", icon, 10000);
emit minimized();}

error: expected primary-expression before ‘*’ token
error: expected primary-expression before ‘)’ token

wysota
30th August 2010, 10:38
Think, don't act blind. First of all the method has two arguments. Second of all use proper C++.

Bong.Da.City
30th August 2010, 10:43
Just think that i am still a beginner... Could you explain me more?

wysota
30th August 2010, 14:41
Just think that i am still a beginner... Could you explain me more?

Run the code I gave you earlier but add the second argument to it, just like the docs say. You have read the reference manual for this method, right? You have seen it takes two arguments and not one like in my code, right? You understand what values you can pass as the second argument, yes?

squidge
31st August 2010, 18:40
Just think that i am still a beginner... Could you explain me more?

Even a beginner to Qt should have a solid knowledge in C++, otherwise you are just going to struggle with it at every turn.