PDA

View Full Version : help with pointers and



sincnarf
1st July 2007, 20:43
Hello!

I am using Qt4.2.3.

Please help me with pointers and correct this piece of code. And if possible, put some explanation on why I enounter errors such as "functional cast expression list treated as compound expression" and "no matching call' errors. Thanks in advance


void MainWinow::doFunction1()
{
QImage *image = new QImage(QSize(100,100), QImage::Format_RGB32);

int x = 0;
int y = 0;
for (x= 0; x < image->width(); x++){
for (y = 0; y < image->height(); y++){
image->setPixel(x, y, QRgb(255,0,0));
}
}

QGraphicsScene *scene = new QGraphicsScene;
QGraphicsPixmapItem *item;
item->setShapeMode(QGraphicsPixmapItem::BoundingRectShap e);
item->setFlag(QGraphicsItem::ItemIsMovable);
scene->addPixmap(QPixmap::fromImage(&image));

//graphicsViewVis is globally declared
graphicsViewVis->setScene(scene);
graphicsViewVis->show();

}

Gopala Krishna
1st July 2007, 21:29
Hello!

I am using Qt4.2.3.

Please help me with pointers and correct this piece of code. And if possible, put some explanation on why I enounter errors such as "functional cast expression list treated as compound expression" and "no matching call' errors. Thanks in advance



scene->addPixmap(QPixmap::fromImage(&image));


Change it to

scene->addPixmap(QPixmap::fromImage(*image));
You are trying to pass QImage** to a function which takes const QImage& as parameter.

jpn
1st July 2007, 21:34
Side notes: there is no need to allocate image on the heap and item is never initialized.

sincnarf
1st July 2007, 22:02
Thanks for the help! I changed the lines 5 to 11 into


int x = 0;
int y = 0;
for (x= 0; x < image.width(); x++){
for (y = 0; y < image.height(); y++){
image.setPixel(x, y, QRgb(255,0,0));
}
}

and it produces the error

mainwindow.cpp:139: error: functional cast expression list treated as compound expression
mainwindow.cpp:139: warning: left-hand operand of comma has no effect
mainwindow.cpp:139: warning: right-hand operand of comma has no effect

Gopala Krishna
2nd July 2007, 05:31
Change line no 3 in your first snippet to
QImage image(QSize(100,100), QImage::Format_RGB32);

sincnarf
2nd July 2007, 14:44
This is my code


void MainWindow::doFunction1()
{
QImage image(QSize(100,100), QImage::Format_RGB32);

int x = 0;
int y = 0;
for (x= 0; x < image.width(); x++){
for (y = 0; y < image.height(); y++){
image.setPixel(x, y, QRgb(255,0,0));
}
}

QGraphicsScene *scene = new QGraphicsScene;
QGraphicsPixmapItem *item;
item->setShapeMode(QGraphicsPixmapItem::BoundingRectShap e);
item->setFlag(QGraphicsItem::ItemIsMovable);
scene->addPixmap(QPixmap::fromImage(image));

graphicsViewVis->setScene(scene);
graphicsViewVis->show();

}


on compilation, there are errors and warnings :
error: functional cast expression list treated as compound expression
warning: left-hand operand of comma has no effect
warning: right-hand operand of comma has no effect

it is noted that the line image.setPixel(x, y, QRgb(255,0,0)); is underlined in red. this is where the error is. Thanks in advance to those who can explain to me how to solve the error functional cast expression list treated as compound expression.

jpn
2nd July 2007, 15:09
It should be "qRgb(255,0,0)". Notice comments in earlier posts; variable "QGraphicsPixmapItem *item" is still used as uninitialized so a crash will follow.