PDA

View Full Version : Why does this QPixmap::fromImage() crash?



jmsbc
20th August 2009, 00:40
Hello, I have the following lines of code:



QImage tImage(50,50,QImage::Format_Indexed8);
tImage.fill(0);
QPixmap tempImagePix = QPixmap::fromImage(tImage);


When I run this it crashes saying:

Debug error!
Module: 4.5.0
File: global\qglobal.cpp
Line:1994

ASSERT failure in QVector<T>::at: "index out of range", file
...\include\qtcore\../../src/corelib/tools/qvector.h, line 327

What is causing the problem? Thank you.

candela
20th August 2009, 04:48
I run this very well. maybe something else is wrong.

franz
20th August 2009, 07:19
Investigate your stack trace when you get this assert failure. That will tell you which part of your code causes this problem.

jmsbc
20th August 2009, 21:35
Well the error is from the last line, fromImage.

When i look at the call stack the error is coming from:
fromImage()-> convertToFormat()-> convert_Indexed8_to_X32()-> QVector <unsigned int>::at(0)

inline const T &QVector<T>::at(int i) const
{ Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::at", "index out of range");
return d->array[i]; }
template <typename T>

I also tried to change the size of my QImage, but same thing. Please help, thank you.

wysota
25th August 2009, 09:26
Aren't you by any chance calling that from an external thread?

jmsbc
25th August 2009, 17:33
The problem was that I didn't have a colormap, which was the array that it was trying to index.

Apparently when I try to use fromImage: "..the image is first converted to a 32-bit pixmap and then filled with the colors in the color table." (Qt documentation)

Which is kind of weird that I need to initialize a color table even though i'm using QImage::Format_Indexed8

wysota
25th August 2009, 21:50
What do you mean by "even though"? If you are using an indexed format then do you need a colour table. It won't get initialized on its own...