[Qt-interest] QImage, QPixmap and zbar

Anatoly Burakov burakov.anatoly at gmail.com
Wed Jun 22 14:52:49 CEST 2011


Hi all!

I'm writing a simple app to encode/decode QR images. I am using the zbar 
library (and its Qt bindings) to handle the decoding process.

However, i'm having a few problems with image formats. To be more 
specific, i'm having trouble understanding what exactly is the 
difference between QImage and QPixmap, why doesn't the image data 
survive conversion to one another, and why they behave in a weird way. 
I'm sure i'm missing something here, but anyway.

I am feeding image data to zbar through drag-n-drop and from clipboard. 
For some reason, for drag-n-drop, zbar only wishes to process images 
generated from QImage (via its own QZBarImage class), feeding a to it 
QPixmap.toImage() does not work. My drag-n-drop code is almost 
word-for-word copy from Qt's own drap-n-drop tutorial 
(http://doc.qt.nokia.com/latest/dnd.html) so i'm sure there's no problem 
there.

Except again, for some reason, reading a QImage from QClipboard::image() 
and feeding it to zbar does not work - but reading a QPixmap (via 
QClipboard::pixmap()) and feeding it to zbar via QPixmap::toImage() does.

It does understand images produced by me which are put into clipboard 
(which are QPixmaps), but i still can't manage to decode them via 
drag-n-drop from my widgets (i am putting QPixmap to 
QMimeData::setImageData(), tried both qvariant_cast to QPixmap and 
QImage, using QImage made from QPixmap::toImage() throws an exception in 
zbar).

Also, i can't paint on a QImage. The following code works fine with QPixmap:

// QGraphicsScene scene
QPixmap result(scene.width(), scene.height());
QPainter painter(&result);
scene.render ( &painter );

When i try to paint on a QImage, the debug message says device is not 
active.

It might be relevant that i'm using Qt 4.7, KDE 4.6.4 libraries and 
running latest Ubuntu 11.04 x64.

That's a lot of questions... So, what am i doing wrong?



More information about the Qt-interest-old mailing list