简体   繁体   English

Qt / C ++不将QGraphicview显示为QWidget

[英]Qt/C++ Not displaying QGraphicview as QWidget

My project consists of operations between geometric figures on a cartesian plane.I would include a graph that have to be updated after each operation. 我的项目包括笛卡尔平面上几何图形之间的操作。我将包括一个必须在每次操作后更新的图形。

Thats the source: 那是来源:

http://pastebin.com/s5Fu9dHJ http://pastebin.com/s5Fu9dHJ

I've created the wrapper "disegna" (: public QWidget) because of I am sending to display everything as separate widgets (I have a widget for the virtual keyboard, another for Qlineedits, etc.) and I need an QWidget object can be used with view-> addWidget (QWidget,int,int) because I cannot pass directly a QMainWindow object. 我已经创建了包装器“disegna”(:public QWidget),因为我发送所有内容作为单独的小部件显示(我有一个用于虚拟键盘的小部件,另一个用于Qlineedits等)我需要一个QWidget对象可以与view-> addWidget(QWidget,int,int)一起使用,因为我无法直接传递QMainWindow对象。

The Program run with no errors,but no "hello world" is drawed (and no blank-space for istance QGraphicView is created). 程序运行时没有错误,但没有绘制“hello world”(并且没有为istance QGraphicView创建空白空间)。

where am I doing it wrong? 我在哪里做错了?

Change 更改

QGraphicsView view(&scene);
view.show();

to

QGraphicsView * view = new QGraphicsView(&scene);
view->show();

The way you have it now, the instance of QGraphicView is allocated on the stack and gets destroyed right after the disegna constructor is executed, that's why you can't see it. 你现在拥有它的方式, QGraphicView的实例被分配在堆栈上,并在执行了disegna构造函数后disegna销毁,这就是你无法看到它的原因。

Don't forget to free the memory. 别忘了释放记忆。

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

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