【问题标题】:Promoting QWidget in Qt creator, problems with constructor在 Qt 创建者中提升 QWidget,构造函数的问题
【发布时间】:2015-11-03 09:28:00
【问题描述】:

我继承了QGraphicsView

class CustomGraphicsView : public QGraphicsView
{
public:
    CustomGraphicsView(QWidget *parent = 0);
...
}

.cpp 文件中的构造函数然后是这样实现的:

CustomGraphicsView::CustomGraphicsView(QWidget * parent):
    QGraphicsView(parent)
{
}

现在我通过 Qt 创建者将 QGraphicsView Widget 提升到 CustomGraphicsView。但是当我想在 ImageWindow 类的构造函数中连接到提升的小部件时;

ImageWindow::ImageWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ImageWindow)
{
    ui->setupUi(this);

    CustomGraphicsView * view = ui->graphicsView();

}

我收到错误消息:

term does not evaluate to a function taking 0 arguments.

我为构造函数指定了一个默认值,即 QWidget *parent = 0,并且在ui_image_window.h 中设置了一个参数:

graphicsView = new CustomGraphicsView(ImageWindow);

那么什么会导致这个错误呢?

【问题讨论】:

    标签: c++ qt qt-creator qwidget


    【解决方案1】:

    这是因为graphicsView 是一个成员而不是一个方法,所以你不需要括号。只需像view = ui->graphicsView 一样访问它。这对于生成的 UI 类中的所有 Qt 小部件都是一样的——它们只是成员,而不是方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      相关资源
      最近更新 更多