PDA

View Full Version : must construct QApplication before constructing QPaintDevice



regix
7th September 2006, 20:50
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 571

Brandybuck
7th September 2006, 22:39
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?

regix
7th September 2006, 22:50
Thanks,

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

regix

dvmorris
20th April 2007, 23:44
Is there anything else that can cause this error?

I am using this bash script (http://qtcentre.org/forum/f-qt-programming-2/t-bad-relink-libs-on-qt4-mac-osx-install-name-tool-6440.html/?highlight=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

wysota
21st April 2007, 00:21
You surely have some global object somewhere which is created before QApplication.

dvmorris
21st April 2007, 00:24
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?

wysota
21st April 2007, 00:33
I have no idea. I don't even know why you use that script. AFAIK Qt can create bundles by itself.

dvmorris
21st April 2007, 00:39
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.

wysota
21st April 2007, 00:42
http://doc.trolltech.com/latest/deployment-mac.html

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

dvmorris
21st April 2007, 00:59
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


/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.0)
/Library/Frameworks/3DconnexionClient.framework/Versions/A/3DconnexionClient (compatibility version 1.0.0, current version 1.0.0)
/usr/local/Trolltech/Qt-4.3.0beta/lib/QtXml.framework/Versions/4/QtXml (compatibility version 4.3.0, current version 4.3.0)
/usr/local/Trolltech/Qt-4.3.0beta/lib/QtOpenGL.framework/Versions/4/QtOpenGL (compatibility version 4.3.0, current version 4.3.0)
/System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 12.0.0)
/usr/local/Trolltech/Qt-4.3.0beta/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.3.0, current version 4.3.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 128.0.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 824.42.0)
/usr/local/Trolltech/Qt-4.3.0beta/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.3.0, current version 4.3.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.6)
/usr/lib/libiconv.2.dylib (compatibility version 5.0.0, current version 5.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 22.0.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

after the script


/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.0)
/Library/Frameworks/3DconnexionClient.framework/Versions/A/3DconnexionClient (compatibility version 1.0.0, current version 1.0.0)
@executable_path/../Frameworks/QtXml.framework/Versions/4/QtXml (compatibility version 4.3.0, current version 4.3.0)
@executable_path/../Frameworks/QtOpenGL.framework/Versions/4/QtOpenGL (compatibility version 4.3.0, current version 4.3.0)
/System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 12.0.0)
@executable_path/../Frameworks/QtGui.framework/Versions/4/QtGui (compatibility version 4.3.0, current version 4.3.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 128.0.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 824.42.0)
@executable_path/../Frameworks/QtCore.framework/Versions/4/QtCore (compatibility version 4.3.0, current version 4.3.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.6)
/usr/lib/libiconv.2.dylib (compatibility version 5.0.0, current version 5.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 22.0.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)


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

wysota
21st April 2007, 01:01
No, the object doesn't have to be static. It's enough if it's global. Maybe your Qt installation is somehow broken?

dvmorris
21st April 2007, 01:06
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

wysota
21st April 2007, 01:21
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.

dvmorris
21st April 2007, 03:43
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

wysota
21st April 2007, 13:16
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.

dvmorris
21st April 2007, 18:46
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:



#!/bin/sh
# Copyright 2006 David Johnson
# The author grants unlimited permission to
# copy, distribute and modify this script

# APPNAME=MyApp

### get system configuration ########################################

# as long as we can find qmake, we don't need QTDIR
FWPATH=`qmake -query QT_INSTALL_LIBS`
if [ ! -d $FWPATH/QtGui.framework ] ; then
echo "ERROR: cannot find the Qt frameworks. Make sure Qt is installed"
echo "and qmake is in your environment path."
exit
fi

### get required user input #########################################

if [ -z $APPNAME ] ; then
echo
echo "This script prepares a Qt application bundle for deployment. It will"
echo "copy over the required Qt frameworks and sets the installation"
echo "identifications. Please see the \"Deploying an Application on Qt/Mac\""
echo "page in the Qt documentation for more information."
echo
echo "This script assumes you have already built the application bundle."
echo
echo -n "What is the name of the application? "
read userinput
APPNAME=$userinput
fi

BUNDLE=$APPNAME.app

if [ ! -d $BUNDLE ] ; then
echo "ERROR: cannot find application bundle \"$BUNDLE\" in current directory"
exit
fi

if [ ! -x $BUNDLE/Contents/MacOS/$APPNAME ] ; then
echo "ERROR: cannot find application in bundle. Did you forget to run make?"
exit
fi

echo "application: $APPNAME"
echo "bundle: $BUNDLE"

### query binary for frameworks #####################################

for n in `otool -L $BUNDLE/Contents/MacOS/$APPNAME | grep Qt` ; do
path=`echo $n | grep Qt`
if [ $path ] ; then
name=`basename $path`
FRAMEWORKS="$FRAMEWORKS $name"
# sanity check
if [ "$path" != "$FWPATH/$name.framework/Versions/4/$name" ] ; then
echo "ERROR: problem with framework paths. Perhaps this script " \
"has already been run?"
exit
fi
fi
done

echo -n "Using frameworks"
for n in $FRAMEWORKS ; do
echo -n " $n"
done
echo

### make install ################################################## ##

# assumes install target populates the application bundle
echo "Running make install"
if [ -e Makefile.Release ] ; then
make -f Makefile.Release install
else
make install
fi
strip $BUNDLE/Contents/MacOS/$APPNAME

### copy over frameworks ############################################

mkdir -p $BUNDLE/Contents/Frameworks
for framework in $FRAMEWORKS ; do
if [ ! -d $FWPATH/$framework.framework ] ; then
echo "ERROR: cannot find $FWPATH/$framework.framework"
exit
fi
echo "Copying $framework framework"
cp -fR $FWPATH/$framework.framework $BUNDLE/Contents/Frameworks
# strip libs (-x is max allowable for shared libs)
strip -x $BUNDLE/Contents/Frameworks/$framework.framework/Versions/4/$framework
done

# remove unwanted parts
find $BUNDLE/Contents/Frameworks | egrep "debug|Headers" | xargs rm -rf

### set the identification names for frameworks #####################

echo -n "Setting framework IDs..."

for framework in $FRAMEWORKS ; do
echo -n " $framework"
install_name_tool \
-id @executable_path/../Frameworks/$framework.framework/Versions/4/$framework \
$BUNDLE/Contents/Frameworks/$framework.framework/Versions/4/$framework
done
echo

### change framework location #######################################

echo -n "Changing framework paths..."
for framework in $FRAMEWORKS ; do
echo -n " $framework"
install_name_tool \
-change $FWPATH/$framework.framework/Versions/4/$framework \
@executable_path/../Frameworks/$framework.framework/Versions/4/$framework \
$BUNDLE/Contents/MacOS/$APPNAME
done
echo

### change location for bundled frameworks #########################

echo -n "Fixing bundled frameworks..."
for framework in $FRAMEWORKS ; do
echo -n " $framework"
fwdeps=""
bundledfw="$BUNDLE/Contents/Frameworks/$framework.framework/Versions/4/$framework"
# get framework dependencies
for n in `otool -LX $bundledfw | grep Qt` ; do
path=`echo $n | grep Qt`
if [ $path ] ; then
name=`basename $path`
fwdeps="$fwdeps $name"
fi
done
# fix dependency location
for dep in $fwdeps ; do
if [ "$dep" != "$framework" ] ; then
install_name_tool \
-change $FWPATH/$dep.framework/Versions/4/$dep \
@executable_path/../Frameworks/$dep.framework/Versions/4/$dep \
$bundledfw
fi
done
done
echo

### create disk image ###############################################

echo "Creating disk image"
imagedir="/tmp/$APPNAME.$$"
mkdir $imagedir
cp -R $BUNDLE $imagedir

# TODO: copy over additional files, if any
hdiutil create -ov -srcfolder $imagedir -format UDBZ -volname "$APPNAME" "$APPNAME.dmg"
rm -rf $imagedir

echo "Done"


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.