[Development] Should null QPixmaps be allowed in a QCoreApplication?
eirik.aavitsland at qt.io
Mon Sep 6 07:52:37 CEST 2021
On 9/3/21 2:38 PM, Sze Howe Koh wrote:
> On Tue, 31 Aug 2021 at 19:22, Eirik Aavitsland <eirik.aavitsland at qt.io> wrote:
>> 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).
> Ah, OK. I only constructed null pixmaps in my test (calling the
> QPixmap constructor with no arguments) and there was no runtime
> So really, it's
> B1) If you create a QPixmap through QPixmap::fromImage()... you get a
> runtime warning and a null QPixmap.
> B2) If you create a _non-null_ QPixmap any other way, you get a
> qFatal() with a message
> B3) If you create a null QPixmap, you get no warnings and have nothing
> to worry about.
> If it's as designed, then I'm happy to leave it (and happy to avoid
> breaking any user code!)
> So to clarify: The answer to my original question is "Yes, null
> QPixmaps are allowed in a QCoreApplication"?
> In that case, isn't the
> qFatal() unnecessary in qt_pixmap_thread_test()?
Possibly it has become so, though I think one would have to look into if
removing it would open up other potential crashes, i.e. possibilities to
hit codepaths that assume the existence of at least a QCoreApplication.
- Eirik Aa.
More information about the Development