简体   繁体   English

Qt Creator C ++,void值不会被忽略,因为它应该被忽略

[英]Qt creator C++, void value is not ignored as it ought to be

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. 我的猜测是警告是由于您分配了一些计算的QPoints的地址。 It will crash even if you get it compiled. 即使将其编译,它也会崩溃。 Just use QList<QPoint> . 只需使用QList<QPoint> It's not that heavy. 没那么重。

If you dereference points[i] you will get a object with type QPoint& . 如果取消引用points[i] ,则将得到一个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 . 产生奇怪错误消息的原因是->的优先级比* ,因此编译器实际上尝试取消引用setX / setY的返回值。

'taking address of temporary' is a very serious condition. “临时地址”是一个非常严重的条件。

You're also unnecessarily dereferencing for the other two errors. 您也不必不必要地取消引用其他两个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM