Results 1 to 12 of 12

Thread: QSystemTrayIcon doesnt seem to emit activated signal on icon click

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSystemTrayIcon doesnt seem to emit activated signal on icon click

    that space was probably added by the forum when i pasted the code, its not on my code here. I am not getting any warnings on the command line, no error, no warnings.

    The implementations of the "trayClicked function is below

    void zuluCrypt::trayClicked(QSystemTrayIcon::Activation Reason e)
    {
    std::cout << "ds" << std::endl ;
    if( e == QSystemTrayIcon::Trigger){

    if(this->isVisible() == true)
    this->hide();
    else
    this->show();
    }
    }

    I am using Qt Creator and that "ds" string would have showed up in the "application output window" if i run the program from within Qt Creator if the function was called.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QSystemTrayIcon doesnt seem to emit activated signal on icon click

    Works fine here:
    Qt Code:
    1. #include <QtGui>
    2. #include <iostream>
    3.  
    4. class MainWindow : public QMainWindow {
    5.  
    6. Q_OBJECT
    7.  
    8. public:
    9. MainWindow(){
    10. QTableWidget *tw = new QTableWidget(3,3,this); // added re: your question above.
    11. setCentralWidget(tw);
    12. QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
    13. trayIcon->setIcon(QIcon("../icons/googleearth-icon.png"));
    14. trayIcon->show();
    15. connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(trayClicked(QSystemTrayIcon::ActivationReason)));
    16. }
    17.  
    18. private slots:
    19. void trayClicked(QSystemTrayIcon::ActivationReason e){
    20. std::cout << "ds" << std::endl;
    21. if( e == QSystemTrayIcon::Trigger){
    22. if(this->isVisible() == true) this->hide();
    23. else this->show();
    24. }
    25. }
    26. };
    27.  
    28.  
    29. int main(int argc, char *argv[]){
    30. QApplication app(argc, argv);
    31. MainWindow w;
    32. w.show();
    33. app.exec();
    34. }
    35.  
    36. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QSystemTrayIcon doesnt seem to emit activated signal on icon click

    Took a look at your app and your problem is that you have your mainwindow (zulucrypt) set to Qt::ApplicationModal

  4. #4
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSystemTrayIcon doesnt seem to emit activated signal on icon click

    I took your code, put in qt creator, build and run it and the tray shows on the system tray but without an icon which is understandable because i dont have that icon in that path but the tray does not respond to clicks but atleast now i have an output and it says:

    Object::connect: No such slot MainWindow::trayClicked(QSystemTrayIcon::Activatio nReason)

    so i guess this is progress.

    What tool did you use to write, build and run the code in? This could be a Qt creator 2.3.1 + Qt 4.7.4 specific issue

  5. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QSystemTrayIcon doesnt seem to emit activated signal on icon click

    Did you read post #8? Try changing the zuluCrypt mainwindow from ApplicationModal to WindowModal and check the behavior.

    Quote Originally Posted by mhogomchungu View Post
    This could be a Qt creator 2.3.1 + Qt 4.7.4 specific issue
    Don't think so. I'm using QtCreator 2.2.1 & Qt 4.7.3 (64 bit).

    Try it from the command line:
    mkdir systraytest && cd systraytest
    touch main.cpp
    open main.cpp with your favorite editor and paste in the code. Save
    qmake -project
    qmake
    make
    ./systraytest

    Again, it works fine on a Debian Sid (KDE) box.

  6. #6
    Join Date
    Oct 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSystemTrayIcon doesnt seem to emit activated signal on icon click

    Quote Originally Posted by mhogomchungu View Post
    I am using Qt Creator and that "ds" string would have showed up in the "application output window" if i run the program from within Qt Creator if the function was called.
    Qt Code:
    1. #include <QDebug>
    2. qDebug() << "ds";
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 12th October 2016, 08:48
  2. programmatically right click on QSystemTrayIcon
    By noa l in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2011, 13:42
  3. signal doesnt emit
    By mark2804 in forum Newbie
    Replies: 2
    Last Post: 25th December 2008, 22:36
  4. emit the activated signal on a combobox
    By Equilibrium in forum Qt Programming
    Replies: 4
    Last Post: 8th November 2007, 12:33
  5. QSystemTrayIcon on click() ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2007, 08:43

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
  •  
Qt is a trademark of The Qt Company.