的QGraphicsView noobie问题

问题描述:

尝试添加文本的QGraphicsView:的QGraphicsView noobie问题

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

    QGraphicsScene scene; 
    scene.addText("Hello, world!"); 
    ui->graphicsView->setScene(&scene); 
} 

但是,当项目运行,没有什么上的QGraphicsView。

您的QGraphicsScene scene是一个局部变量,它在Widget的构造函数执行完后会立即被删除。

将场景更改为Widget类的私有成员变量。