I derive a subclass from QMainWindow, I want to set the QGraphicsView object as the mainwindow's centralWidget, like below:

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QApplication a(argc, argv);
  4. test w;
  5. w.show();
  6. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
  7. return a.exec();
  8. }
  9.  
  10. test::test(QWidget *parent, Qt::WFlags flags)
  11. : QMainWindow(parent, flags)
  12. {
  13. ui.setupUi(this);
  14.  
  15. QPixmap pixCT;
  16. pixCT.load("Resources/CT.bmp");
  17. QGraphicsView view(&scene, this);
  18. setCentralWidget(&view);
  19. scene.addPixmap(pixCT);
  20. //view.show();
  21. }
To copy to clipboard, switch view to plain text mode 

But it doesn't work. What should I do to solve this problem ?

Thank you very much for helping!