QImage::fill can't digest what I feed it
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?
Re: QImage::fill can't digest what I feed it
Curious. GCC compiles this without issue on Linux and Windows, as you would expect.
Code:
#include <QtGui>
int main(int argc, char **argv)
{
qim.
fill( QColor("#FFD07F") );
return 0;
}
Does your compiler choke on the example above?
Re: QImage::fill can't digest what I feed it
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
Re: QImage::fill can't digest what I feed it
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.
Re: QImage::fill can't digest what I feed it
Qt 4.7.4 has no a function which takes QColor in QImage::fill. That method was introduced in Qt 4.8 as Ginsengelf said above.
Re: QImage::fill can't digest what I feed it
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?
Re: QImage::fill can't digest what I feed it
use qRgba or QColor::rgba.