Bug 502740

Summary: KStatusNotifierItem has no associated window when initializing in parent constructor because no native window exists
Product: [Frameworks and Libraries] frameworks-kstatusnotifieritem Reporter: Marcel Hasler <mahasler>
Component: generalAssignee: Alexander Lohnau <alexander.lohnau>
Status: REPORTED ---    
Severity: normal    
Priority: NOR    
Version First Reported In: 6.12.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Marcel Hasler 2025-04-13 12:06:54 UTC
SUMMARY

When a KStatusNotifierItem is constructed e.g. from the main-window constructor, passing the main window as parent, the expected behavior of showing/hiding the main window on activation no longer works. This is because at this point no native window has been created yet, i.e. windowHandle() returns nullptr. Therefore the KStatusNotifierItem doesn't get any associated window.

This is a regression and likely has to do with the changes of using associatedWindow instead of associatedWidget, but possibly also to later changes in QMainWindow or KMainWindow behavior.

Possible workarounds include calling show() or setVisible(true) from the main-window c'tor before creating the KStatusNotifierItem or deferring creation until after the window becomes visible. However, I feel that these are rather clumsy (especially for applications that should start minimized to the system tray) and the issue really should be handled correctly by KStatusNotifierItem itself.


STEPS TO REPRODUCE
1. Construct KStatusNotifierItem in main-window c'tor, passing main window as parent
2. Click on notifier item in system tray

OBSERVED RESULT
Nothing happens

EXPECTED RESULT
Main window should show/hide

SOFTWARE/OS VERSIONS
Linux: 6.12.21-1-lts 
KDE Plasma Version: 6.3.4
KDE Frameworks Version: 6.12.0
Qt Version: 6.9.0

ADDITIONAL INFORMATION
This also happens on another system with Frameworks 6.12.0 and Qt 6.8.3, so it probably isn't related to any recent changes in Qt.