Bug 396287

Summary: qqc2-desktop-style crashing when QApplication::style() returns NULL
Product: [Frameworks and Libraries] frameworks-qqc2-desktop-style Reporter: RJVB <rjvbertin>
Component: generalAssignee: Marco Martin <notmart>
Status: RESOLVED FIXED    
Severity: crash CC: kde
Priority: NOR    
Version: 5.47.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: All   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: possible crash avoidance

Description RJVB 2018-07-07 21:13:15 UTC
Steps to reproduce:

- build Qt's example applications
- launch the quickcontrols2/gallery/gallery example
- set settings/Style to org.kde.desktop and restart
Comment 1 David Edmundson 2018-07-07 21:36:59 UTC
It will.

Don't use QQC2-desktop-style without a QApplication as it needs the QStyle.
Comment 2 RJVB 2018-07-07 22:34:53 UTC
Well, that really puts a huge damper on using this plugin; setting QT_QUICK_CONTROLS_STYLE=org.kde.desktop means random (from the user's PoV) applications will start to crash.

Letting code crash like this is really sloppy too, IMHO. Apparently it's not possible to let the style plugin deactivate itself when `qApp->style() == NULL`, but it can at least provoke a more or less clean application exit by not registering anything in registerTypes. And maybe it's not that expensive to let the style become a big NOOP in this situation.
Comment 3 RJVB 2018-07-08 21:01:27 UTC
Created attachment 113842 [details]
possible crash avoidance

This is a simple workaround to prevent applications from crashing.
I haven't found a more elegant workaround (like a fallback to the default QQ2 style) but IMHO this still beats letting the code dereference null pointers knowingly.
Comment 4 David Edmundson 2018-07-09 12:34:12 UTC
Patch makes sense. 

Maybe QApplication::style as its static and qApp isn't a QApplication.

Ship it.
Comment 5 RJVB 2018-11-24 09:35:49 UTC
Git commit 1e02355c178600e89b8c45e6232b2a2dc811ccc6 by René J.V. Bertin.
Committed on 24/11/2018 at 09:35.
Pushed by rjvbb into branch 'master'.

Support for QGuiApplication-based apps

Wraps qApp->style() and creates a QStyle instance of the user's preferred
widget style if qApp->style() returns null. This makes it safe to set
QT_QUICK_CONTROLS_STYLE=org.kde.desktop and still run applications based
on QuickControls2 (QGuiApplication) without crashing.
Differential Revision: https://phabricator.kde.org/D14000

M  +139  -117  plugin/kquickstyleitem.cpp
M  +7    -2    plugin/kquickstyleitem_p.h

https://commits.kde.org/qqc2-desktop-style/1e02355c178600e89b8c45e6232b2a2dc811ccc6