0

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

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.

The Program run with no errors,but no "hello world" is drawed (and no blank-space for istance QGraphicView is created).

where am I doing it wrong?

1 Answers1

2

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.

Don't forget to free the memory.

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
  • Thank you,I am so tired that I forget that.It runs ok but there are 2 windows (one as before and the new one with the QGraphicview istance).How can I include this one as a QWidget on the MAIN layout? –  Aug 16 '12 at 22:38
  • Solved! This is the final source to display my QGraphicView into a QMainWindow disegna::disegna(QWidget *parent) : QWidget(parent) { scene.addText("19 11"); QGraphicsRectItem* myrect = scene.addRect(QRectF(0,0,50,50),QPen(), QBrush()); scene.setForegroundBrush(QBrush(Qt::blue, Qt::CrossPattern)); scene.addRect(QRectF(0, 0, 700, 300)); QGraphicsView * view = new QGraphicsView(&scene,this); view->show(); } Thank you again Now i could go to bed (12hours of study!) –  Aug 16 '12 at 23:57