Results 1 to 17 of 17

Thread: QWidget: Must construct a QApplication before a QPaintDevice

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget: Must construct a QApplication before a QPaintDevice

    Quote Originally Posted by elcuco View Post
    I am linking statically
    Maybe Qwt uses a different version of Qt libraries?

  2. #2
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget: Must construct a QApplication before a QPaintDevice

    Quote Originally Posted by jacek View Post
    Maybe Qwt uses a different version of Qt libraries?
    Often, this is the cause for my problems.

    In release mode, I must add -lqwt to LIBS, where in debug mode, -lqwtd should be added. Here a snippet of my .pro file:

    Qt Code:
    1. #LIBS+= -lqwt #Release
    2. LIBS+= -lqwtd #Debug
    To copy to clipboard, switch view to plain text mode 

    Cheers, Bilderbikkel

  3. #3
    Join Date
    Jun 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget: Must construct a QApplication before a QPaintDevice

    If you are using a static Widget and not on purpose there is an easy solution. All you have to do is remove the parent class parenthesis.

    Qt Code:
    1. class MyQtWidget(QtGui.QWidget())
    To copy to clipboard, switch view to plain text mode 

    change to

    Qt Code:
    1. class MyQtWidget(QtGui.QWidget)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QWidget: Must construct a QApplication before a QPaintDevice

    Perhaps you compiled "xyz" in debug mode and application in release mode?
    Man, this stupid thing just nailed me for two days. When I set up my release mode build in Visual Studio, I copied the list of libraries from the debug settings, then carefully edited all of the "d" suffixes off. On all but two libraries...

    For the first day, I couldn't figure out what was happening - the app wouldn't even get into main(). You could see it start in Task Manager, then it immediately exited. No error message, no crash, nothing. Finally thought to link it with debug turned on, and saw the "QPixmap: Must construct a QGuiApplication first" message. Spent a wasted hour looking for QPixmap, and of course there aren't any defined as static in my code. Finally came across this thread and thought, "I wonder if I've been stupid..."

    So, for anyone else using Visual Studio or the MSVC compilers to build your Qt projects, you can't mix debug and release libraries or debug libraries and a release executable. If you get the incomprehensible "QPixmap: Must construct..." error, it means that's what you've done.

  5. #5
    Join Date
    Jul 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget: Must construct a QApplication before a QPaintDevice

    d_stranz is right - I had all my libs with a 'd' at the end except for Qt5Widgets and it was causing an error in setupUi() that said: Must construct a QGuiApplication before QPixmap. Thanks for the tipoff guys!

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QWidget: Must construct a QApplication before a QPaintDevice

    Thanks for the tipoff guys!
    Yes, but I continue to be stupid. This time, I had a bare-bones QApplication I had just written. Added a few lines to the MainWindow constructor to set some things up (pushing std:: wstring constants onto a std:: vector< std:: wstring > >) and it kept crashing with a heap corruption error. After another wasted hour, discovered it was a mismatch of release and debug libraries yet again.

    This nasty bug keeps appearing in different disguises. I guess the take-away lesson is that if you have perfectly good code that won't run, it has nothing to do with the code, it's the way you're building it. Hopefully I'll be quicker to realize that next time.

Similar Threads

  1. Replies: 15
    Last Post: 21st April 2007, 17:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.