[Qt-interest] QWidget: Must construct a QApplication before a QPaintDevice
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Tue Sep 1 10:22:20 CEST 2009
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Andre Somers
Sent: Tuesday, September 01, 2009 12:41 AM
To: Qt-interest
Subject: Re: [Qt-interest] QWidget: Must construct a QApplication before a QPaintDevice
Andreas Pakulat wrote:
On 31.08.09 17:22:36, Andre Somers wrote:
Hi,
I am experiencing a weird problem. When I compile my program with the
release flag, I get the above error if I run it through the debugger. If
I run it directly, it aborts with a code 3. However, when I compile a
debug version of my program, the problem does not occur.
The problem is weird anyway, because in my main function, the first
thing I do is construct a QApplication. Here is my main function:
main() is not necessarily the "first" thing, static objects are created
before main, so you should check your code for any widgets created as
static objects. Or other "global" variables you create on the stack in
some .cpp file.
Andreas
Thank you for your input.
My application does not use static objects. That is, there are a few static pointers (for use in singleton classes), but that's it. These singletons are not instantiated before the QApplication. What's more, I only see this crash at a point where a window is initialized. I have succesfully loaded some plugins, and only then the crash happens. But this plugin loading only happens *after* a QApplication instance has been constructed!
So, I am seeing this issue at a moment that I am sure a QApplication has already been constructred.
Brad Howes wrote:
What compiler/OS are you running on? In my experience, crashes that
occur in an optimized build (I assume that is what you mean by
'release') vs. a debug build happen due to uninitialized memory or
invalid parameter count -- a quite common one in my C days was printf
() bugs. For C++, a couple of things come to mind: uninitialized POD
members, invalid assumptions on object lifetimes, race condition.
First of all, good point Brad, I forgot to mention my platform. I am working on Windows XP using MinGW32.
What I mean by debug and release, is simply setting the these flags in QtCreator. I am not manually adjusting any optimization flags. The point was the specific message that is printed to my console: "QWidget: Must construct a QApplication before a QPaintDevice". I really don't get how that can occur, as a QApplication //has// been constructed, and I verified that by printing a message with QApplication::applicationDirPath() (using my app variable) and the sessionId to the console using qDebug(). This message appears neatly in the output where I would expect it: right at the top of my output.
I would really appreciate any more pointers, especially on how I can debug a case like this that only appears in release mode. I now feel like I am stumbeling around in the dark...
Thanks!
André
------------------------------
Put a breakpoint at the warning message inside QWIdgets constructor...
You will then track down who the culprit is
Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090901/bd43442a/attachment.html
More information about the Qt-interest-old
mailing list