PDA

View Full Version : How to show Multiple Message using QSystemTrayIcon?



ashukla
21st May 2009, 12:40
foreach (QString str, msgData) {
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon();
this->showMessage(tr("Alert"), str, icon);
sleep(2);
}
The above code doesn't display all the message. Only the last alert is visible. How to display all the alerts.

jpujolf
21st May 2009, 12:57
Try adding this line of code ( not tested, but I think it must do the work... )



foreach (QString str, msgData) {
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon();
this->showMessage(tr("Alert"), str, icon);
QCoreApplication::processEvents(); // <= THIS LINE
sleep(2);
}

Lykurg
21st May 2009, 12:58
sleep(2);

Wow, that will block your whole application! Better use a QTimer.

ashukla
22nd May 2009, 05:34
foreach (QString str, msgData) {
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon();
this->showMessage(tr("Alert"), str, icon);
QCoreApplication::processEvents(); // <= THIS LINE
sleep(2);
}
the output is same as previous.

ashukla
22nd May 2009, 05:35
Wow, that will block your whole application! Better use a QTimer.

Where I put this timer?

Lykurg
22nd May 2009, 10:26
the output is same as previous.

because of your sleep(). First it is only possible to display one message. So if you have more you must place them with time elapse.


Store all messages in a QQueue.
call a showMyMessages(): if the queue in not empty and the timer is not running display the message and start a timer which calls the same function again in X seconds. if no message are left stop timer.