QList<QPoint*> DrawingWidget::getCloseLinesById(int m_x, int m_y) {
QList<QPoint*> lines;
// HERE I APPEND ABOUT 5 ITEMS
return lines;
}
The appending works here. It only gives me a few warnings, but it still compiles. The warning is.
taking address of temporary
But this
void DrawingWidget::mouseMoveEvent(QMouseEvent *event) {
if(m_mainWindow->getSelectedTool() == MainWindow::moveVertexTool) {
m_x = event->x();
m_y = event->y();
QList<QPoint*> points = getCloseLinesById(event->x(), event->y());
for(int i = 0; i < points.size(); i++) {
*points[i]->setX(event->x()); //error on this line
*points[i]->setY(event->y()); // error on this line
}
update();
}
}
}
result in these errors:
void value not ignored as it ought to be
void value not ignored as it ought to be
So it gives the same error for both lines.
This code should basically move my lines when I move my mouse.
How can I fix this problem?
You didn't state what exactly is your question. But you are using extra *
in your errored lines:
points[i]->setX(event->x());
Also, you didn't show how you append to the list. My guess is the warning is from you assigning addresses of some computed QPoints. It will crash even if you get it compiled. Just use QList<QPoint>
. It's not that heavy.
If you dereference points[i]
you will get a object with type QPoint&
. You cant use the ->
operator on non-pointer types (that is unless the type provides custom definition of the ->
operator).
So removing the *
in front of those two lines should fix the error.
The reason for the strange error messages is, that ->
has a higher precedence than *
, so the compiler actually tries to dereference the return value of setX
/ setY
.
'taking address of temporary' is a very serious condition.
You're also unnecessarily dereferencing for the other two errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.