QSystemTrayIcon sometimes can't show



  • Hi,

    This is my code executed in MainWindow constructor:

    @private:
    QSystemTrayIcon mTray;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    mTray.setIcon(QIcon(":/images/22/player_play.png"));
    mTray.setVisible(true);
    }@

    On every ~3 try tray icon only blink and show in left-top corner of the screen instead of tray bar. It is better when I move code to the main method (between qapplication and main window create) . Then problem occur on every ~7 try.
    When I move this code to button click and change it to mTray.setVisible(not mTray.isVisible()); then even with very fast clicking it is working all time. Any idea?

    I have Linux KDE 64bit. Qt 5.1

    Regards



  • From the doc's, I think you are looking for
    @
    private:
    QSystemTrayIcon *mTray;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    mTray = new QSystemTrayIcon(this);
    // look at the other allocation methods, I think you can pass in the icon to remove the next line
    mTray->setIcon(QIcon(":/images/22/player_play.png"));
    mTray->show();
    }
    @

    Look at this example:
    http://harmattan-dev.nokia.com/docs/library/html/qt4/desktop-systray.html

    I usually use a pointer / malloc



  • Tried with pointer in main window too, but same problem. But I moved trayicon construction to main proc now and use pointer. Seems problem solved.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.