Results 1 to 16 of 16

Thread: Problem using System Tray Icon....

  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool Problem using System Tray Icon....

    Hi i am trying to make a System Tray Icon to be shown everytime i minimize my application......
    Qt Code:
    1. if (isMinimized()) {
    2. trayIcon->show();
    3. enum MessageIcon { NoIcon, Information, Warning, Critical };
    4. QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(Information);
    5. trayIcon->showMessage("titlos", "mplampla", icon, 10000);
    6. emit minimized();}
    To copy to clipboard, switch view to plain text mode 

    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?
    Attached Images Attached Images

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using System Tray Icon....

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using System Tray Icon....

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using System Tray Icon....

    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)

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using System Tray Icon....

    Quote Originally Posted by Bong.Da.City View Post
    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
    Qt Code:
    1. QApplication::sendPostedEvents(trayIcon);
    To copy to clipboard, switch view to plain text mode 
    after calling show() on the tray icon object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using System Tray Icon....

    I had found an example from here.. 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.. systrayl.zip

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using System Tray Icon....

    Quote Originally Posted by Bong.Da.City View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using System Tray Icon....

    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... ?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using System Tray Icon....

    I have already told you what to do. Read post #5 in this thread again.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using System Tray Icon....

    It doesn't work.. look at the code.. is it what you mean?

    Qt Code:
    1. if (isMinimized()) {
    2. trayIcon->show();
    3. QApplication::sendPostedEvents(trayIcon);
    4. emit minimized();
    5. enum MessageIcon { NoIcon, Information, Warning, Critical };
    6. QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(Information);
    7. trayIcon->showMessage("titlos", "mplampla", icon, 10000);
    8. }
    To copy to clipboard, switch view to plain text mode 

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

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using System Tray Icon....

    Quote Originally Posted by Bong.Da.City View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using System Tray Icon....

    Qt Code:
    1. if (isMinimized()) {
    2. trayIcon->show();
    3. QCoreApplication::sendPostedEvents(QSystemTrayIcon*&);
    4. enum MessageIcon { NoIcon, Information, Warning, Critical };
    5. QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(Information);
    6. trayIcon->showMessage("titlos", "mplampla", icon, 10000);
    7. emit minimized();}
    To copy to clipboard, switch view to plain text mode 

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

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using System Tray Icon....

    Think, don't act blind. First of all the method has two arguments. Second of all use proper C++.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using System Tray Icon....

    Just think that i am still a beginner... Could you explain me more?

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using System Tray Icon....

    Quote Originally Posted by Bong.Da.City View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using System Tray Icon....

    Quote Originally Posted by Bong.Da.City View Post
    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.

Similar Threads

  1. system tray message is not displaying near tary icon
    By sudhansu in forum Qt Programming
    Replies: 0
    Last Post: 29th March 2010, 17:31
  2. How to keep System tray icons
    By mkkguru in forum Qt Programming
    Replies: 10
    Last Post: 24th February 2010, 16:19
  3. How to write some text next to the system tray icon?
    By alex chpenst in forum Qt Programming
    Replies: 3
    Last Post: 5th September 2008, 08:43
  4. Replies: 4
    Last Post: 30th June 2008, 06:25
  5. system tray problem
    By vvdounai in forum Qt Programming
    Replies: 5
    Last Post: 14th November 2007, 08:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.