Re: help with pointers and
Quote:
Originally Posted by
sincnarf
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
Code:
scene
->addPixmap
(QPixmap::fromImage(&image
));
Change it to
Code:
scene
->addPixmap
(QPixmap::fromImage(*image
));
You are trying to pass QImage** to a function which takes const QImage& as parameter.
Re: help with pointers and
Side notes: there is no need to allocate image on the heap and item is never initialized.
Re: help with pointers and
Thanks for the help! I changed the lines 5 to 11 into
Code:
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
Re: help with pointers and
Change line no 3 in your first snippet to
Re: help with pointers and an error I dont' know of
This is my code
Code:
void MainWindow::doFunction1()
{
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));
}
}
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.
Re: help with pointers and
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.