Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Win toast / balloon notifications stopped working recently on windows 10 with Qt



  • To me it seems windows balloon messages stopped working completely some weeks ago on windows 10. In August 2019 the following code based on Qt could be used to post a notification in the windows action center, and letting a toast pop up with that notification:

    #include <QApplication>
    #include <QSystemTrayIcon>
    
    int main(int argc, char **argv)
    {
        QApplication app( argc, argv );
    
        //create a notification icon, and post a test notification
        QSystemTrayIcon *trayTest = new QSystemTrayIcon();
        trayTest->setIcon( QIcon( "path-to-some-icon-resource" ) );
        trayTest->show();
        trayTest->showMessage( "Hello", "world" );
    
        return app.exec();
    }
    

    But now out of the blue QSystemTrayIcon::showMessage stopped having any effect at all, and nothing is showing up anywhere. A systray application at work is using that method, and windows notifications stopped working on all systems (with windows 10 installed). QSystemTrayIcon::showMessage isn't working with Qt 5.7, Qt 5.12 and Qt 5.13. I had a look on the source of Qt 5.7, and internally Shell_NotifyIcon is called in qsystemtrayicon_win.cpp:

    bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
    {
        NOTIFYICONDATA tnd;
        memset(&tnd, 0, notifyIconSize);
        qStringToLimitedWCharArray(message, tnd.szInfo, 256);
        qStringToLimitedWCharArray(title, tnd.szInfoTitle, 64);
    
        tnd.uID = q_uNOTIFYICONID;
        tnd.dwInfoFlags = iconFlag(type);
        tnd.cbSize = notifyIconSize;
        tnd.hWnd = m_hwnd;
        tnd.uTimeout = uSecs;
        tnd.uFlags = NIF_INFO | NIF_SHOWTIP;
    
        return Shell_NotifyIcon(NIM_MODIFY, &tnd);
    }
    

    Shell_NotifyIcon is used across different versions of Qt for the windows implementation of showMessage. I verified that Shell_NotifyIcon was called when calling QSystemTrayIcon::showMessage under Qt 5.7, it returned 1 like it should if no errors had occurred, and no notification was showing up. Playing around with the "Focus assist" and "Notifications & actions" settings had no effect.

    Have there been windows updates recently modifying the behavior of windows notifications? Is it only possible to post notifications with some new native windows 10 apis? I couldn't find anything concerning windows updates and notifications not showing anymore.


  • Lifetime Qt Champion

    Hi,

    Does it work for you if you call the native API directly in your application ?


  • Lifetime Qt Champion

    Hi
    tried your code (Qt 5.12.6) in winVer1803 which is rather old now.
    I didnt update to 1903 as had many issues at work with it.

    No toast was shown using your code. ( I did assign valid icon)

    So in what version did you actually see that code work ?



  • @mrjj said in Win toast / balloon notifications stopped working recently on windows 10 with Qt:

    Hi
    tried your code (Qt 5.12.6) in winVer1803 which is rather old now.
    I didnt update to 1903 as had many issues at work with it.

    No toast was shown using your code. ( I did assign valid icon)

    So in what version did you actually see that code work ?

    I saw the code work on Windows 10 Enterprise winVer1803 in August. Now still on winVer1803 (with hotfixes KB4512576, KB4516115, KB4521861, KB4523203, KB4525237 installed in the meantime) it's not working as I said. But recently I tested the code on Windows 10 winVer1903, and it worked on Qt 5.7 and Qt 5.12, the test notification was showing up! It doesn't make any sense to me. I might have to try using the new Windows 10 api to post the notifications, which is ugly or maybe impossible with using Visual Studio 2015.