Search code examples
c++qtdrawqgraphicsviewqwidget

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

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?


Solution

  • 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.