[Development] Should null QPixmaps be allowed in a QCoreApplication?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Tue Jul 27 19:04:20 CEST 2021


Il 27/07/21 18:41, Sze Howe Koh ha scritto:
> 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 [1].
> 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.
> 
> 
> I think that results of (B) and (C) should be changed to match (D) [2]. 
> However, there are some complications:
> 
> * There is a unit test that relies on the current behaviour of (B) [3].
> * Making this change will break existing user code that relies on the 
> current behaviour of (B).
> 
> How should we proceed?

If you need anything GUI related, a QGuiApplication is necessary (if you 
don't have a display server, use the offscreen QPA).

B) is "wrong" in the measure in which it's UB-land, so the silent 
behavior is technically fine. I wouldn't mind to be more verbose and 
aligning B+C to D. If a test depends on it, change the test?

Thanks,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20210727/68cb3f1f/attachment-0001.bin>


More information about the Development mailing list