babu198649
18th March 2009, 12:45
Hi
The following line of code gives error
QLinearGradient grad(rect().topLeft() + (rect().topLeft()-rect().bottomLeft()) / 2,
(rect().topRight()-rect().bottomRight()) / 2);
grad.setColorAt(0.0,0x000000); //Gives error
The error is
mainwindow.cpp: In member function ‘virtual void MainWindow::paintEvent(QPaintEvent*)’:
mainwindow.cpp:103: error: conversion from ‘int’ to ‘const QColor’ is ambiguous
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:79: note: candidates are: QColor::QColor(QColor::Spec) <near match>
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:252: note: QColor::QColor(const char*)
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:75: note: QColor::QColor(QRgb)
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:73: note: QColor::QColor(Qt::GlobalColor) <near match>
But when i modify the statement to
grad.setColorAt(0.0,0x000001); //No error - changed 0x000000 to 0x000001
I get no error.
why does this happen?.Is it so because the compiler sees enum as ints(please correct me if i am wrong). If that is the case then there can not be two constructors with enum arguments to a class as in QColor (QColor(Qt::GlobalColor color) and QColor(Spec spec)).
The following line of code gives error
QLinearGradient grad(rect().topLeft() + (rect().topLeft()-rect().bottomLeft()) / 2,
(rect().topRight()-rect().bottomRight()) / 2);
grad.setColorAt(0.0,0x000000); //Gives error
The error is
mainwindow.cpp: In member function ‘virtual void MainWindow::paintEvent(QPaintEvent*)’:
mainwindow.cpp:103: error: conversion from ‘int’ to ‘const QColor’ is ambiguous
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:79: note: candidates are: QColor::QColor(QColor::Spec) <near match>
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:252: note: QColor::QColor(const char*)
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:75: note: QColor::QColor(QRgb)
../../qtsdk-2009.01/qt/include/QtGui/qcolor.h:73: note: QColor::QColor(Qt::GlobalColor) <near match>
But when i modify the statement to
grad.setColorAt(0.0,0x000001); //No error - changed 0x000000 to 0x000001
I get no error.
why does this happen?.Is it so because the compiler sees enum as ints(please correct me if i am wrong). If that is the case then there can not be two constructors with enum arguments to a class as in QColor (QColor(Qt::GlobalColor color) and QColor(Spec spec)).