Qt-interest Archive, May 2008
Constructing a QPixmap in main ()after QApplication is constructed fails
Message 1 in thread
This code
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(application);
QApplication app(argc, argv);
QPixmap pm(some_xpm);
MainWindow mainWin;
mainWin.show();
return app.exec();
}
results in
ASSERT failure in QVector<T>::operator[]: "index out of range",
file ../../include/QtCore/../../src/corelib/tools/qvector.h, line 324
Aborted
and is due to construction of the QPixmap (I have simply added this
line to one of the Qt4 examples "examples/mainwindows/application")
This is Qt 4.3.4( Ubuntu Hardy Heron)
What's going on ?
This certainly worked in Qt3.x.
I can't see anything in the documentation that suggests that
there should be a problem.
The reason that this cropped up is that my application loads a bunch
of plugins after QApplication is constructed and these each initialise
a pixmap - which then causes a crash.
As you may guess I am porting from Qt3 to Qt4 ...
Cheers
Michael
--
[ signature omitted ]
Message 2 in thread
On 21 maj 2008, at 14.33, Michael Wouters wrote:
> This code
>
> int main(int argc, char *argv[])
> {
> Q_INIT_RESOURCE(application);
>
> QApplication app(argc, argv);
>
> QPixmap pm(some_xpm);
>
pm is created here, but is not used anywhere within main.
What do you expect to happen, when you don't make it available
anywhere else?
> MainWindow mainWin;
> mainWin.show();
>
> return app.exec();
> }
>
> results in
>
> ASSERT failure in QVector<T>::operator[]: "index out of range",
> file ../../include/QtCore/../../src/corelib/tools/qvector.h, line 324
> Aborted
>
> and is due to construction of the QPixmap (I have simply added this
> line to one of the Qt4 examples "examples/mainwindows/application")
>
> This is Qt 4.3.4( Ubuntu Hardy Heron)
>
> What's going on ?
> This certainly worked in Qt3.x.
> I can't see anything in the documentation that suggests that
> there should be a problem.
>
> The reason that this cropped up is that my application loads a bunch
> of plugins after QApplication is constructed and these each initialise
> a pixmap - which then causes a crash.
>
> As you may guess I am porting from Qt3 to Qt4 ...
>
> Cheers
> Michael
>
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
-----------------------------------
See the amazing new SF reel: Invasion of the man eating cucumbers from
outer space.
On congratulations for a fantastic parody, the producer replies :
"What parody?"
Tommy Nordgren
tommy.nordgren@xxxxxxxxx
--
[ signature omitted ]
Message 3 in thread
On Wed, 2008-05-21 at 14:44 +0200, Tommy Nordgren wrote:
> On 21 maj 2008, at 14.33, Michael Wouters wrote:
>
> > This code
> >
> > int main(int argc, char *argv[])
> > {
> > Q_INIT_RESOURCE(application);
> >
> > QApplication app(argc, argv);
> >
> > QPixmap pm(some_xpm);
> >
> pm is created here, but is not used anywhere within main.
> What do you expect to happen, when you don't make it available
> anywhere else?
> > MainWindow mainWin;
> > mainWin.show();
> >
> > return app.exec();
> > }
> >
That's right, pm is not used anywhere else but causes a segfault
simply by being instantiated. I don't think this should happen. If
you create the pixmap before the QApplication then you get the
expected behaviour viz a warning about no QPainter and then the
app exits. But I think it should be OK to create a pixmap after the
QApplication. It worked in Qt3.x.
The code above is just meant to be a simple demonstration of the
problem.
In my actual application, I load a bunch of plugins after instancing
my QApplication, and these create pixmaps when they are loaded. The
first plugin that is loaded then causes a crash when it creates a
pixmap.
Cheers
Michael
> -----------------------------------
> See the amazing new SF reel: Invasion of the man eating cucumbers from
> outer space.
> On congratulations for a fantastic parody, the producer replies :
> "What parody?"
>
> Tommy Nordgren
> tommy.nordgren@xxxxxxxxx
>
>
--
[ signature omitted ]