Important: Please read the Qt Code of Conduct -

QGraphicsView inside QMainWindow does not work ? (all code snippet pasted)

  • I've no idea why the main window does not display the intended text, yet only blank ?

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        QGraphicsScene scene;
        scene.addText("Hello, world!");
        QGraphicsView *view = new QGraphicsView(this);

  • Moderators

    Your scene object is on the stack, so it will be destroyed when the constructor exits.

    Kind regards.

  • Right.
    This is not the first time I made such mistake. So the lifecycle of GraphicsScene is required for graphics view.

    Thanks for the help. This is solved.