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

    I had one global variable, declared before main:

    long double curValue[36];

    But removing it still left me with the same problem. The only thing that I can think of is that there is something in MainWindowImpl.h which is causing this problem, since thats the only thing that comes before main, as far as I can tell. I'm posting it here, if you wouldnt mind looking through it and telling me if it could be causing problems.

    Qt Code:
    1. #ifndef MAINWINDOWIMPL_H
    2. #define MAINWINDOWIMPL_H
    3. //
    4. #include <QMainWindow>
    5. #include "ui_mainwindow.h"
    6. //
    7.  
    8.  
    9. class MainWindowImpl : public QMainWindow, public Ui::MainWindow
    10. {
    11. Q_OBJECT
    12. public:
    13. MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    14. void refreshDisplay(int,long double curValue[36]);
    15. private:
    16.  
    17. bool bLatch;
    18. int maxValue[36];
    19. bool bCheckable[36][2];
    20. private slots:
    21. public slots:
    22. void bumpUp1();
    23. void bumpUpRETURN1();
    24. void bumpDn1();
    25. void bumpDnRETURN1();
    26. void linkLx1();
    27. void slideLx1(int);
    28.  
    29. void bumpUp2();
    30. void bumpUpRETURN2();
    31. void bumpDn2();
    32. void bumpDnRETURN2();
    33. void linkLx2();
    34. void slideLx2(int);
    35.  
    36. void bumpUp3();
    37. void bumpUpRETURN3();
    38. void bumpDn3();
    39. void bumpDnRETURN3();
    40. void linkLx3();
    41. void slideLx3(int);
    42.  
    43. void bumpUp4();
    44. void bumpUpRETURN4();
    45. void bumpDn4();
    46. void bumpDnRETURN4();
    47. void linkLx4();
    48. void slideLx4(int);
    49.  
    50. void bumpUp5();
    51. void bumpUpRETURN5();
    52. void bumpDn5();
    53. void bumpDnRETURN5();
    54. void linkLx5();
    55. void slideLx5(int);
    56.  
    57. void bumpUp6();
    58. void bumpUpRETURN6();
    59. void bumpDn6();
    60. void bumpDnRETURN6();
    61. void linkLx6();
    62. void slideLx6(int);
    63.  
    64. void bumpUp7();
    65. void bumpUpRETURN7();
    66. void bumpDn7();
    67. void bumpDnRETURN7();
    68. void linkLx7();
    69. void slideLx7(int);
    70.  
    71. void bumpUp8();
    72. void bumpUpRETURN8();
    73. void bumpDn8();
    74. void bumpDnRETURN8();
    75. void linkLx8();
    76. void slideLx8(int);
    77.  
    78. void pressGM();
    79. void slideGM(int);
    80. void checkLatch();
    81.  
    82. void options();
    83.  
    84. };
    85.  
    86. class linkSlide
    87. {
    88. private:
    89. void slideLink(int,int);
    90.  
    91. public:
    92. void slideFunct(int,int,int);
    93. void linkFunct(int);
    94. void slideGM(int);
    95. };
    96.  
    97. class BumpLatch
    98. {
    99.  
    100. public:
    101. bool checkable;
    102. int bumpUp(int,int);
    103. int bumpUpRETURN(int);
    104. int bumpDn(int,int);
    105. int bumpDnRETURN(int);
    106. void latch(bool);
    107.  
    108. };
    109.  
    110.  
    111. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Posts
    25
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Must construct QApplication before QPaintDevice

    I don't see anything interesting there... What is Ui::MainWindow?

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

    Default Re: Must construct QApplication before QPaintDevice

    That was created by QDevelop in the initial project creation. I believe it is the UI file from QT Designer, but I'm not sure.

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

    Did you check if you have static keyword anywhere in your code?

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

  6. #6
    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?

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

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

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

  10. #10
    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?

  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
    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)?

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

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.