Results 1 to 16 of 16

Thread: must construct QApplication before constructing QPaintDevice

  1. #1
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default must construct QApplication before constructing QPaintDevice

    Hi,

    I am making a simple testproject and I get this message when I run the project wich compiled fine.

    Must construct a QApplication before a QPaintDevice

    In the code you can see that I construct a QApplication before anything else.

    ????

    regix Archief.tar.bz2

  2. #2
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    You have a static ImageToHtml object (last line of testcodec.cpp). Static objects are created before the main() function is entered. Since ImageToHtml is a widget (a paint device), it gets created before QApplication.

    That last line is useless. Is it a typo?

  3. #3
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    Thanks,

    I must have been blind to not see that.
    Probably it was not visible in the editor I was using.
    thanks anyway.

    regix

  4. #4
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    Is there anything else that can cause this error?

    I am using this bash script (http://qtcentre.org/forum/f-qt-progr...ighlight=qtxml) which embeds 4 Qt frameworks into the app and makes it into a dmg file, and once I do that, I receive this error. Before I embed the frameworks I do not get this error.

    I can't seem to find any other reason why it would be caused. If anyone has any ideas let me know.
    thanks for the help,
    dave

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: must construct QApplication before constructing QPaintDevice

    You surely have some global object somewhere which is created before QApplication.

  6. #6
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    so that means that it must be outside of any class definition? I really can't find it. Why would it work before embedding the frameworks though?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: must construct QApplication before constructing QPaintDevice

    I have no idea. I don't even know why you use that script. AFAIK Qt can create bundles by itself.

  8. #8
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    I've never seen anything on the Qt documentation about making dmg's. I found the script here originally:

    http://qtnode.net/wiki/Distributing_Mac_Qt_applications

    The script even says the guy who created it doesn't use it anymore, but I've never found a better way to do it. Do you have any suggestions. All I really need it for is to embed the QtCore, QtXml, QtOpenGL, and QtGui frameworks into my .app.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: must construct QApplication before constructing QPaintDevice

    http://doc.trolltech.com/latest/deployment-mac.html

    Anyway that's not the issue here. There is something wrong with your code.

  10. #10
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    I really don't see anything wrong with it. Will it definitely have the word static in it? The code is way too large to post up here, so I guess I'll just keep looking. I don't understand why it works with the absolute paths to the libraries, but not with the relative paths.

    One thing I noticed that this script does that seems strange is in the results of

    otool -L

    before the script
    Qt Code:
    1. /Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.0)
    2. /Library/Frameworks/3DconnexionClient.framework/Versions/A/3DconnexionClient (compatibility version 1.0.0, current version 1.0.0)
    3. /usr/local/Trolltech/Qt-4.3.0beta/lib/QtXml.framework/Versions/4/QtXml (compatibility version 4.3.0, current version 4.3.0)
    4. /usr/local/Trolltech/Qt-4.3.0beta/lib/QtOpenGL.framework/Versions/4/QtOpenGL (compatibility version 4.3.0, current version 4.3.0)
    5. /System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 12.0.0)
    6. /usr/local/Trolltech/Qt-4.3.0beta/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.3.0, current version 4.3.0)
    7. /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 128.0.0)
    8. /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 824.42.0)
    9. /usr/local/Trolltech/Qt-4.3.0beta/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.3.0, current version 4.3.0)
    10. /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
    11. /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.6)
    12. /usr/lib/libiconv.2.dylib (compatibility version 5.0.0, current version 5.0.0)
    13. /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 22.0.0)
    14. /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
    15. /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
    16. /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
    17. /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    To copy to clipboard, switch view to plain text mode 

    after the script
    Qt Code:
    1. /Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.0)
    2. /Library/Frameworks/3DconnexionClient.framework/Versions/A/3DconnexionClient (compatibility version 1.0.0, current version 1.0.0)
    3. @executable_path/../Frameworks/QtXml.framework/Versions/4/QtXml (compatibility version 4.3.0, current version 4.3.0)
    4. @executable_path/../Frameworks/QtOpenGL.framework/Versions/4/QtOpenGL (compatibility version 4.3.0, current version 4.3.0)
    5. /System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 12.0.0)
    6. @executable_path/../Frameworks/QtGui.framework/Versions/4/QtGui (compatibility version 4.3.0, current version 4.3.0)
    7. /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 128.0.0)
    8. /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 824.42.0)
    9. @executable_path/../Frameworks/QtCore.framework/Versions/4/QtCore (compatibility version 4.3.0, current version 4.3.0)
    10. /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
    11. /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.6)
    12. /usr/lib/libiconv.2.dylib (compatibility version 5.0.0, current version 5.0.0)
    13. /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 22.0.0)
    14. /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
    15. /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
    16. /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
    17. /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    To copy to clipboard, switch view to plain text mode 

    saying @executable_path seems wrong, but I don't really know enough about it to know whether that's right or not.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: must construct QApplication before constructing QPaintDevice

    No, the object doesn't have to be static. It's enough if it's global. Maybe your Qt installation is somehow broken?

  12. #12
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    it's 4.3 beta, but 4.2.3 had other errors that I couldn't figure out, and I found this post that said someone fixed the same errors I was having by upgrading to 4.3beta, so I did, and it fixed those errors, but gave me new ones.

    oh joy. i really appreciate all your help. Changing my app to Qt from fltk has been a rollercoaster ride so far. thanks again,
    dave

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: must construct QApplication before constructing QPaintDevice

    Try running your script on a dummy application and see if the problem persists. If so, this could mean a somehow invalid Qt installation or a problem with the script. But if it works, then surely the problem lies within your code.

  14. #14
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    I just tried on an example app , the 2dpainting opengl sample, and it did the same error. that's good to know. Now I just need to find a better script. Perhaps it's the order of the frameworks that I'm including that is the problem. I figured QtCore would need to be first...

    I will try a different script. Thanks for your help,
    dave

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: must construct QApplication before constructing QPaintDevice

    The script might be fine. If it's in the wiki then I assume it works for someone. The problem may lie in cooperation between the script and your Qt compilation.

  16. #16
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: must construct QApplication before constructing QPaintDevice

    I found a different version of a script that does essentially the same thing, but it's a little more robust, and it works perfectly. Here it is:

    Qt Code:
    1. #!/bin/sh
    2. # Copyright 2006 David Johnson
    3. # The author grants unlimited permission to
    4. # copy, distribute and modify this script
    5.  
    6. # APPNAME=MyApp
    7.  
    8. ### get system configuration ########################################
    9.  
    10. # as long as we can find qmake, we don't need QTDIR
    11. FWPATH=`qmake -query QT_INSTALL_LIBS`
    12. if [ ! -d $FWPATH/QtGui.framework ] ; then
    13. echo "ERROR: cannot find the Qt frameworks. Make sure Qt is installed"
    14. echo "and qmake is in your environment path."
    15. exit
    16. fi
    17.  
    18. ### get required user input #########################################
    19.  
    20. if [ -z $APPNAME ] ; then
    21. echo
    22. echo "This script prepares a Qt application bundle for deployment. It will"
    23. echo "copy over the required Qt frameworks and sets the installation"
    24. echo "identifications. Please see the \"Deploying an Application on Qt/Mac\""
    25. echo "page in the Qt documentation for more information."
    26. echo
    27. echo "This script assumes you have already built the application bundle."
    28. echo
    29. echo -n "What is the name of the application? "
    30. read userinput
    31. APPNAME=$userinput
    32. fi
    33.  
    34. BUNDLE=$APPNAME.app
    35.  
    36. if [ ! -d $BUNDLE ] ; then
    37. echo "ERROR: cannot find application bundle \"$BUNDLE\" in current directory"
    38. exit
    39. fi
    40.  
    41. if [ ! -x $BUNDLE/Contents/MacOS/$APPNAME ] ; then
    42. echo "ERROR: cannot find application in bundle. Did you forget to run make?"
    43. exit
    44. fi
    45.  
    46. echo "application: $APPNAME"
    47. echo "bundle: $BUNDLE"
    48.  
    49. ### query binary for frameworks #####################################
    50.  
    51. for n in `otool -L $BUNDLE/Contents/MacOS/$APPNAME | grep Qt` ; do
    52. path=`echo $n | grep Qt`
    53. if [ $path ] ; then
    54. name=`basename $path`
    55. FRAMEWORKS="$FRAMEWORKS $name"
    56. # sanity check
    57. if [ "$path" != "$FWPATH/$name.framework/Versions/4/$name" ] ; then
    58. echo "ERROR: problem with framework paths. Perhaps this script " \
    59. "has already been run?"
    60. exit
    61. fi
    62. fi
    63. done
    64.  
    65. echo -n "Using frameworks"
    66. for n in $FRAMEWORKS ; do
    67. echo -n " $n"
    68. done
    69. echo
    70.  
    71. ### make install ####################################################
    72.  
    73. # assumes install target populates the application bundle
    74. echo "Running make install"
    75. if [ -e Makefile.Release ] ; then
    76. make -f Makefile.Release install
    77. else
    78. make install
    79. fi
    80. strip $BUNDLE/Contents/MacOS/$APPNAME
    81.  
    82. ### copy over frameworks ############################################
    83.  
    84. mkdir -p $BUNDLE/Contents/Frameworks
    85. for framework in $FRAMEWORKS ; do
    86. if [ ! -d $FWPATH/$framework.framework ] ; then
    87. echo "ERROR: cannot find $FWPATH/$framework.framework"
    88. exit
    89. fi
    90. echo "Copying $framework framework"
    91. cp -fR $FWPATH/$framework.framework $BUNDLE/Contents/Frameworks
    92. # strip libs (-x is max allowable for shared libs)
    93. strip -x $BUNDLE/Contents/Frameworks/$framework.framework/Versions/4/$framework
    94. done
    95.  
    96. # remove unwanted parts
    97. find $BUNDLE/Contents/Frameworks | egrep "debug|Headers" | xargs rm -rf
    98.  
    99. ### set the identification names for frameworks #####################
    100.  
    101. echo -n "Setting framework IDs..."
    102.  
    103. for framework in $FRAMEWORKS ; do
    104. echo -n " $framework"
    105. install_name_tool \
    106. -id @executable_path/../Frameworks/$framework.framework/Versions/4/$framework \
    107. $BUNDLE/Contents/Frameworks/$framework.framework/Versions/4/$framework
    108. done
    109. echo
    110.  
    111. ### change framework location #######################################
    112.  
    113. echo -n "Changing framework paths..."
    114. for framework in $FRAMEWORKS ; do
    115. echo -n " $framework"
    116. install_name_tool \
    117. -change $FWPATH/$framework.framework/Versions/4/$framework \
    118. @executable_path/../Frameworks/$framework.framework/Versions/4/$framework \
    119. $BUNDLE/Contents/MacOS/$APPNAME
    120. done
    121. echo
    122.  
    123. ### change location for bundled frameworks #########################
    124.  
    125. echo -n "Fixing bundled frameworks..."
    126. for framework in $FRAMEWORKS ; do
    127. echo -n " $framework"
    128. fwdeps=""
    129. bundledfw="$BUNDLE/Contents/Frameworks/$framework.framework/Versions/4/$framework"
    130. # get framework dependencies
    131. for n in `otool -LX $bundledfw | grep Qt` ; do
    132. path=`echo $n | grep Qt`
    133. if [ $path ] ; then
    134. name=`basename $path`
    135. fwdeps="$fwdeps $name"
    136. fi
    137. done
    138. # fix dependency location
    139. for dep in $fwdeps ; do
    140. if [ "$dep" != "$framework" ] ; then
    141. install_name_tool \
    142. -change $FWPATH/$dep.framework/Versions/4/$dep \
    143. @executable_path/../Frameworks/$dep.framework/Versions/4/$dep \
    144. $bundledfw
    145. fi
    146. done
    147. done
    148. echo
    149.  
    150. ### create disk image ###############################################
    151.  
    152. echo "Creating disk image"
    153. imagedir="/tmp/$APPNAME.$$"
    154. mkdir $imagedir
    155. cp -R $BUNDLE $imagedir
    156.  
    157. # TODO: copy over additional files, if any
    158. hdiutil create -ov -srcfolder $imagedir -format UDBZ -volname "$APPNAME" "$APPNAME.dmg"
    159. rm -rf $imagedir
    160.  
    161. echo "Done"
    To copy to clipboard, switch view to plain text mode 

    i believe my problem with the other script was the order of the list of Qt Frameworks to embed. I always put QtCore first, and this script it written to search for the dependencies and include them in that order, and QtCore seems to come up last, and QtXml first. I won't bother trying the other one again, because this one is a better script all around anyways.

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.