+ Reply to Thread
Results 1 to 14 of 14

Thread: QWidget: Must construct a QApplication before a QPaintDevice

  1. #1
    Join Date
    Jan 2006
    Posts
    356
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QWidget: Must construct a QApplication before a QPaintDevice

    Hi all,

    I am getting this error on my application, even before main() is executed:
    Qt Code:
    1. QWidget: Must construct a QApplication before a QPaintDevice
    To copy to clipboard, switch view to plain text mode 

    The funny (?) thing is that I only get it when choosing "debug and build" in QDevelop's menus. When compiling for release it works flawlessly. Any ideas?

    Here is my main, not even the first line (line number 9 in this code) is printed:
    Qt Code:
    1. #include <cstdlib>
    2. #include "mainwindowimpl.h"
    3. #include <QApplication>
    4.  
    5. using namespace std;
    6.  
    7. int main(int argc, char ** argv)
    8. {
    9. printf("111111111111");
    10. QApplication app( argc, argv );
    11. MainWindowImpl win;
    12. win.show();
    13. app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    Here is the generated faulty pro file
    Qt Code:
    1. TEMPLATE = app
    2. QT = gui core
    3. CONFIG += qt warn_on console debug_and_release
    4. OBJECTS_DIR = build
    5. MOC_DIR = build
    6. UI_DIR = build
    7. FORMS = ui/mainwindow.ui
    8. HEADERS = src/mainwindowimpl.h
    9. SOURCES = src/mainwindowimpl.cpp src/main.cpp
    10. INCLUDEPATH = d:\source\qwt-5.0.2\src
    11. LIBS = d:\source\qwt-5.0.2\lib\libqwt5.a
    To copy to clipboard, switch view to plain text mode 

    Here is the working pro file:
    Qt Code:
    1. TEMPLATE = app
    2. QT = gui core
    3. CONFIG += qt warn_on console release
    4. OBJECTS_DIR = build
    5. MOC_DIR = build
    6. UI_DIR = build
    7. FORMS = ui/mainwindow.ui
    8. HEADERS = src/mainwindowimpl.h
    9. SOURCES = src/mainwindowimpl.cpp src/main.cpp
    10. INCLUDEPATH = d:\source\qwt-5.0.2\src
    11. LIBS = d:\source\qwt-5.0.2\lib\libqwt5.a
    To copy to clipboard, switch view to plain text mode 

    System is MingW, Xp, Qt 4.3.2, QDevelop 0.25.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 537 Times in 520 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Do you have any static QWidgets in your application? Static objects are instantiated before main gets control.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,505 Times in 1,383 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

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

    Alternatively, debug and release object files might be getting mixed. Try cleaning and then rebuilding the project.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Posts
    356
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Cleaning the project and re-building does not help. This means that (probably) the problem is a static widgets.

    I am using QWT, can anyone tell me if it contains a static widget? (I am linking statically).

  5. #5
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Qwt itself does not contain static widgets.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,505 Times in 1,383 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

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

    Perhaps you compiled Qwt in debug mode and application in release mode?
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 973 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?

  8. #8
    Join Date
    Feb 2009
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

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

    Quote Originally Posted by elcuco View Post
    I am linking statically
    In qwtconfig.pri

    CONFIG += QwtDll this line must be ->
    #CONFIG += QwtDll

  9. #9
    Join Date
    Jul 2008
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

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

    Quote Originally Posted by jpn View Post
    Perhaps you compiled Qwt in debug mode and application in release mode?
    it is the answer!!

  10. #10
    Join Date
    Aug 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    hi

    i have the same problem. i use qt-4.5.2 and qwt 5.2 on winXP. i tried all my code in linux and all works fine.

    can anybody of you tell me the procedure on how to compile first qt and then qwt , in the right way?? i don't know why i get these problem! please!

    thank you in advance

  11. #11
    Join Date
    Nov 2012
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X

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

    Hi... i also have a similar question.. what if my application doesnot have any main function.. how would i construct QApplication???? Any idea????
    I am using firebreath integrated with QT library it doesnt have any main function and i am using QMacCocoaViewContainer during the compilation its giving me same error "QWidget Must construct a QApplication before a QPaintDevice" how should i declare QApplication

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    30,863
    Thanks
    3
    Thanked 4,622 Times in 4,427 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

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

    Quote Originally Posted by Saurabh Singh View Post
    what if my application doesnot have any main function..
    Then it is not an application.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    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

  14. #14
    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 

+ Reply to Thread

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