Bug 502740 - KStatusNotifierItem has no associated window when initializing in parent constructor because no native window exists
Summary: KStatusNotifierItem has no associated window when initializing in parent cons...
Status: REPORTED
Alias: None
Product: frameworks-kstatusnotifieritem
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: 6.12.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Alexander Lohnau
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-13 12:06 UTC by Marcel Hasler
Modified: 2025-04-13 12:06 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.