Results 1 to 17 of 17

Thread: Must construct QApplication before QPaintDevice

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Must construct QApplication before QPaintDevice

    Ahh, yes, sorry. I did a file search for any occurrence of "static", nothing turned up.

    Was it a poor choice to declare my other classes within MainWindowImpl.h? I've noticed that if I remove all of the other classes, I can execute, but I suppose that could mean many things.

  2. #2
    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: Must construct QApplication before QPaintDevice

    Quote Originally Posted by sekatsim View Post
    Was it a poor choice to declare my other classes within MainWindowImpl.h?
    No, it shouldn't be a problem.

    Quote Originally Posted by sekatsim View Post
    I've noticed that if I remove all of the other classes, I can execute, but I suppose that could mean many things.
    This means that the problem is in one of those removed classes. Do you use threads?

  3. #3
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Must construct QApplication before QPaintDevice

    I've got two versions of the project now. I got stuck on this QApplication problem, so I backed it up and went back to an earlier version, from before I rearranged the functions. I've added threading to that one, as per my other post. But no. No threading in this version.

    I've removed those classes one by one, in a few different orders, to figure out what might be causing the problem. But it doesnt really seem to be resolved until I remove all of them. Most of those classes do make adjustments to QWidgets.. i.e. setting and restoring slider values, etc, but I see no reason why those classes would be run before main.

    Is there any way I can prohibit all "QApplication" type activities until the window has been drawn? I could try making a unique .h file for main.cpp, that only has the MainWindowImpl class.. but I fear it may screw me up down the road.

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

    Default Re: Must construct QApplication before QPaintDevice

    Is it all in a single project or do you have app + lib? If so, make sure both are compiled in same mode, release vs. debug.
    J-P Nurmi

  5. #5
    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: Must construct QApplication before QPaintDevice

    Quote Originally Posted by jpn View Post
    Is it all in a single project or do you have app + lib? If so, make sure both are compiled in same mode, release vs. debug.
    Good point. Other possibility is that the application is compiled in debug mode and linked with the release version of Qt.

  6. #6
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Must construct QApplication before QPaintDevice

    It's all in one project, and unless I've been specifically trying to solve a problem, I've been compiling in release mode. I think I found the problem, but I'm not quite sure why it was the problem:

    I moved many of my functions outside of the mainwindowimpl class, but when they were done functioning, I wanted them to call refreshDisplay within mainwindowimpl to update all of my sliders/buttons etc. So I had

    MainWindowImpl mainwin;
    mainwin.refreshDisplay();

    As far as I can tell, this is whats causing the problem. Is there anyway I can get around this?

  7. #7
    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: Must construct QApplication before QPaintDevice

    Quote Originally Posted by sekatsim View Post
    MainWindowImpl mainwin;
    mainwin.refreshDisplay();

    As far as I can tell, this is whats causing the problem. Is there anyway I can get around this?
    Do I understand correctly that you invoke refreshDisplay() before QApplication::exec()?

    Maybe the error message is a bit misleading and you should try:
    Qt Code:
    1. MainWindowImpl mainwin;
    2. QTimer::singleShot( 0, & mainwin, "refreshDisplay" );
    To copy to clipboard, switch view to plain text mode 
    (provided that refreshDisplay() is a slot)?

  8. #8
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Must construct QApplication before QPaintDevice

    No, thats the thing, I dont *execute it*, persay, before QApplication::exec(), but it occurs in classes that are defined before QApplication::exec(). It seems like just having an instance of that class causes it to evaluate it and return an error.

    So I guess I would suggest to anyone else having this problem to remove any instance of MainWindowImpl (or whatever your main QWidget drawing class is) that occurs outside of itself.

  9. #9
    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: Must construct QApplication before QPaintDevice

    Quote Originally Posted by sekatsim View Post
    No, thats the thing, I dont *execute it*, persay, before QApplication::exec(), but it occurs in classes that are defined before QApplication::exec(). It seems like just having an instance of that class causes it to evaluate it and return an error.
    So if you put "MainWindowImpl mainwin;" in your main(), you get the error and if you comment it out the error disappears?

  10. #10
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Must construct QApplication before QPaintDevice

    Exactly. I dont understand why. But at least I know to avoid it now

  11. #11
    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: Must construct QApplication before QPaintDevice

    Quote Originally Posted by sekatsim View Post
    Exactly. I dont understand why. But at least I know to avoid it now
    It shouldn't behave this way. Does the error appear when you comment out all of the code in MainWindowImpl constructor?

Similar Threads

  1. Replies: 16
    Last Post: 12th December 2014, 20:22
  2. 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
  •  
Qt is a trademark of The Qt Company.