Results 1 to 9 of 9

Thread: QSystemTrayIcon thread issue

  1. #1
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Wink QSystemTrayIcon thread issue

    I am running into a situation where I create a QSystemTrayIcon in the constructor of the main widget. But when I try to call show on it, it outputs about a dozen "Cannot move to target thread" messages. It still displays and is usable, but it is disconcerting to get any error messages. Here is the code:
    Qt Code:
    1. IngestorGUI::IngestorGUI()
    2. {
    3. if(QSystemTrayIcon::isSystemTrayAvailable())
    4. {
    5. m_ptr_SystemTrayIcon = new QSystemTrayIcon();
    6. m_TrayIcon = QIcon("dmax_icon.png");
    7. m_ptr_SystemTrayIconContextMenu = new QMenu(this);
    8. m_ptr_actShowGui = new QAction(this);
    9. m_ptr_actShowGui->setText("Show Interface");
    10. m_ptr_actShowGui->setCheckable(true);
    11. connect(m_ptr_actShowGui,SIGNAL(changed()),this,SLOT(slotShowInterface()));
    12. m_ptr_SystemTrayIconContextMenu->addAction(m_ptr_actShowGui);
    13. m_ptr_SystemTrayIcon->setIcon(m_TrayIcon);
    14. m_ptr_SystemTrayIcon->setContextMenu(m_ptr_SystemTrayIconContextMenu);
    15. m_ptr_SystemTrayIcon->show();
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    On a side note; Is there any way to force explorer to update the system tray when I shut down? It never seems to update until I mouse over it. I tried to hide the icon before deleting, but it still didn't update. here is my destructor code:
    Qt Code:
    1. IngestorGUI::~IngestorGUI()
    2. {
    3. if(m_ptr_actShowGui != (QAction*) NULL)
    4. {
    5. delete m_ptr_actShowGui;
    6. }
    7. if(m_ptr_SystemTrayIconContextMenu != (QMenu*) NULL)
    8. {
    9. delete m_ptr_SystemTrayIconContextMenu;
    10. }
    11. if(m_ptr_SystemTrayIcon != (QSystemTrayIcon*)NULL)
    12. {
    13. m_ptr_SystemTrayIcon->hide();
    14. delete m_ptr_SystemTrayIcon;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: QSystemTrayIcon thread issue

    Are you using threads in your application?

  3. #3
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Wink Re: QSystemTrayIcon thread issue

    I will be, but not yet. Right now this IngestorGUI object is created in main along with a QApplication. The QApplication is then executed. Here is the main code:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. IngestorGUI window;
    6.  
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: QSystemTrayIcon thread issue

    Can you create a minimal example that only creates the tray icon and calls exec() on the application object and see if the problem persists? BTW. Which version of Qt are you using?

  5. #5
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSystemTrayIcon thread issue

    4.3.1

    I will try that and post back.

    EDIT: The issue persists on the minimal example.

  6. #6
    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: QSystemTrayIcon thread issue

    This might be a bug in Qt. You might check if it was reported in the task-tracker.

  7. #7
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSystemTrayIcon thread issue

    Doesn't seem to be. Can anyone corroborate this issue on their system?

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSystemTrayIcon thread issue

    Could you post the minimal example? System Tray Icon Example gives me no warnings at all with Qt/Win 4.3.1.
    J-P Nurmi

  9. #9
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSystemTrayIcon thread issue

    Qt Code:
    1. #include <QApplication>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. syst.setIcon(QIcon("dmax_icon.png"));
    7. syst.show();
    8.  
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    put the icon of your choice in place of the png

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  2. Replies: 10
    Last Post: 20th March 2007, 23:19
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 01:49
  4. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 12:02
  5. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:44

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.