[Development] Should null QPixmaps be allowed in a QCoreApplication?
eirik.aavitsland at qt.io
Tue Aug 31 13:18:32 CEST 2021
On 7/27/21 6:41 PM, Sze Howe Koh wrote:
> Current Qt behaviours:
> A) If you create any QPixmap after creating QGuiApplication, the result
> is probably the pixmap that you asked for. All is well.
> B) If you create any QPixmap after creating QCoreApplication, the result
> is a null QPixmap. No warnings are produced.
> C) If you create any QPixmap _in a secondary thread_ after creating
> QCoreApplication, the result is a segfault due to a nullptr dereference .
> D) If you create any QPixmap without creating Q(Core|Gui|)Application,
> the result is a qFatal() telling you that you must have a QGuiApplication.
The description of B) is not quite correct I think. The actual behaviour
is that, if you have a QCoreApplication, then
B1) If you create a QPixmap through QPixmap::fromImage(), either
directly or indirectly via QVariant or reading from QDataStream, you get
a runtime warning and a null QPixmap.
B2) If you create a QPixmap any other way, you get a qFatal() with a
message, i.e. same as D).
Now the logs indicate that the exception for the B1 situation is there
to let headless, QCoreApplication-based apps handle QDataStreams that
may contain QPixmaps without crashing. DBus is mentioned as a case. This
is the reason there is an autotest that explicitly ensures this
behaviour. It was clearly done intentionally.
What is anyway clear is that behaviour C) is not intended and is a bug.
So C) can and should be fixed; to behave the same as B), I think.
- Eirik Aa.
More information about the Development