[Qt-interest] QImageWriter says JPEG supported, but won't write JPEG Files

Josiah Bryan jbryan at productiveconcepts.com
Thu Oct 29 17:07:31 CET 2009


Hey All -

I can't seem to get QImageWriter to write out JPEG files, even though 
the supportedImageFormats() list gives jpeg/jpg as a supported format! 
(Qt "4.7.0" and 4.5.2 both exhibit this problem)

I don't get any errors from the QImageWriter API, but the message on the 
console is:

QJpegHandler: unable to write image of format 7

And the resulting file is "empty" (13k of random data.)

The list given by QImageWriter::supportedImageFormats() outputs this:

("BW", "EPS", "EPSF", "EPSI", "PCX", "RGB", "RGBA", "SGI", "TGA", "bmp", 
"bw", "eps", "epsf", "epsi", "ico", "jp2", "jpeg", "jpg", "pcx", "png", 
"ppm", "rgb", "rgba", "sgi", "tga", "tif", "tiff", "xbm", "xpm", "xv")

Here's the code I'm using, grabbing a pixmap from a widget and saving to 
a file. (QPixmap::save() gave the same 'unable to write image of format 
7' message, so I switched to QImageWriter hopeing that the errorString() 
or canWrite() method would show some problems. Nope.)

Here's the offending code: Any ideas on how to fix?


	QList<QByteArray> list = QImageWriter::supportedImageFormats();
	qDebug()<<"ImageWriter format list: "<<list;
	
	qDebug("Starting frame grab...");
	QPixmap frame = QPixmap::grabWidget(m_viewer);
	
	QImageWriter writer("/tmp/test.jpg");
	if(!writer.canWrite())
	{
		qDebug() << "ImageWriter can't write!";
	}
	else
	if(!writer.write(frame.toImage()))
	{
		qDebug() << "ImageWriter reported error:"<<writer.errorString();
	}

Thanks!
-josiah

-- 

-=-=-=-=-=-=-=-=-=-=-=-=-
Josiah Bryan
Productive Concepts, Inc.
jbryan at pciint.com
(765) 964-6009, ext. 224




More information about the Qt-interest-old mailing list