2015-11-03 37 views
-1

问题,我划分子类QGraphicsViewQt Creator中促进了QWidget,用构造

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

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

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

现在我通过提拔了的QGraphicsView的Widget一个Qt创建者到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的*父= 0的默认值,并在ui_image_window.h一个参数被设置:

graphicsView = new CustomGraphicsView(ImageWindow); 

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

回答

2

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

+0

F **** CK!这花了我很多时间。我认为这是一个返回指针的方法:(谢谢! – newandlost