Questions about Windows notifications in Qt
-
Hi evereyone,
I try to add some Windows notification to my application and interract with it. For that, I strated by use the good systray turorial provide by Qt.
I use these functionalities on my program and it works well. I also add a function that create a pop up message when I click on my notification.
However, I have some questions for which I didn't find answers:
- The duration parameters of showMessage function doesn't seem to work on Windows 10. Is it normal ? Does it exist a solution for this ?
- Once the notification is over, it remains on the Windows notification center (like for e-mail notifications). However, when I click on it, the associated function I created doesn't work. What is the possible solutions to make it works ?
Note that the pop up message function works very well during the 5 second while the notification appears.
-
Hi
The docs say
"On Windows, the millisecondsTimeoutHint is usually ignored by the system when the application has focus."
So i don't think its "fixable"- Once the notification is over, it remains on the Windows notification center
Hmm, the systray tutorial works for me and reacts to being click when inside the center.
You could try and see if it does for you too.
If yes, it means you have some error in the app code and if you need help to find it, you need to show it :)
-
@mrjj
Thank you for your answer. If I understand well, based on the systray tutorial code, the following lines are related to the programme reaction when the user click on the notification:Regarding the initialization function:
Window::Window() { ... connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Window::messageClicked); ... }
Regarding the action to do on click:
void Window::notificationClicked() { QMessageBox::information(nullptr, tr("Systray"), tr("Sorry, I already gave what help I could.\n" "Maybe you should try asking a human?")); }
So this code works well while the notification appear, weither if I click on it directly or in the notification center. After 5 second (when the notification disappear), it still remains in the notification center, however nothing happen when I click on it (even in the systray tutorial).
I tried it on two computer using Windows 10. Both give the same results. You say it works for you ?
-
Hi
yes it works if we agree on the notification center, being this
it then opens a sidebarand clicking on the msg there will show the same "ask a human" dialog.this is with Qt 5.15, Win 10 .
So if it doesn't work for you, I would guess on older Qt, or Qt6, or the newest win 10. 21h2.
UPDATE:
No. i was wrong. clicking it does not trigger the dialog. -
@mrjj
We agree on this.
I'm on Qt 5.12.2 and I run the program trhough Qt creator 4.15.1. My Windows version is 20H2. On the both computer where I tested it.So I'm a little bit confused about you saying it works on your device.EDIT : Ok, it is a kind of a relief. So do you have any clues why ?
-
@CLBSII
Hi
Sadly I was not able to find any information regarding if its should work or not or
it did work at some point.
I looked in bugs Db for QSystemTrayIcon::messageClicked
but I cannot find any indication of other users ever noticed this,
https://bugreports.qt.io/browse/QTBUG-45803?jql=text ~ "QSystemTrayIcon"I wonder if something like
https://github.com/mohabouje/WinToast
could be a solution. -
@mrjj
That is unfortunate .... anyway thank you for the help !I will investigate this library. I already tried something similar in Python without success. Hoping this one will work.
For now I keep this topic open just in case someone find a solution to this issue.