PDA

View Full Version : QImage::fill can't digest what I feed it



darenw
1st August 2012, 23:30
I am stumped by this compile error, sure that it's some very simple "obvious" doof-up. I'm hoping to create an image filled with a color.

QImage qim( QSize(24,24), QImage::Format_ARGB32 );
qim.fill( QColor("#FFD07F") );

The compiler from Visual Studio 10 (using command line tools) gripes with:

main.cpp(51) : error C2664: 'QImage::fill' : cannot convert parameter 1 from 'QColor' to 'uint'

Line 51 being the qim.fill() call. The Qt doc for QImage says QImage::fille(const QColor &) exists, and QColor should be fine with a string containing web-style color like that. It sure looks like everything is fine in the source code.

What the heck is the problem?

ChrisW67
2nd August 2012, 06:26
Curious. GCC compiles this without issue on Linux and Windows, as you would expect.


#include <QtGui>

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QImage qim( QSize(24,24), QImage::Format_ARGB32 );
qim.fill( QColor("#FFD07F") );
return 0;
}

Does your compiler choke on the example above?

Ginsengelf
2nd August 2012, 09:40
Hi, which Qt version do you use?
QImage::fill(const QColor & color) has been introduced with Qt 4.8, so if you use an earlier version, you compiler is correct :)

Ginsengelf

darenw
2nd August 2012, 18:59
Yes, my compiler, from Visual Studio 10, chokes on that simple example. Qt is 4.7.4 on a 64-bit Windows 7 machine.
Here is the error:


.\c.cpp(7) : error C2664: 'QImage::fill' : cannot convert parameter 1 from 'QColor' to 'uint'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\x86_amd64\cl.EXE"' : return code '0x
2'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.


It should be noted that I am a long-time linux user, familiar with gcc and clang (and some obscure tools on unix-like platforms). My most recent experience with anything Microsoft goes back to 2001 or so, not counting the current job and some minor incidents, so I'm ignorant of the various quirks of the system. I build by writing C++ source, running qmake -project, qmake and nmake.

BTW, s/fille/fill/ in the OP. Fat clumsy fingers, I have.

spirit
2nd August 2012, 19:03
Qt 4.7.4 has no a function which takes QColor in QImage::fill (http://doc.qt.nokia.com/4.7/qimage.html#fill). That method was introduced in Qt 4.8 (http://qt-project.org/doc/qt-4.8/qimage.html#fill-3) as Ginsengelf said above.

darenw
2nd August 2012, 19:15
Astonishing! Seems like feeding a QColor to fill() would be such an obvious basic act it would have been in Qt since 0.x versions. Oh well.

So, what's the easy no-brainer workaround in 4.7?

spirit
2nd August 2012, 19:21
use qRgba or QColor::rgba.