Hi all,

I face a problem in Qt, QDeclarativeView can not delete after constructing via pointer. It throws an exception: Segmentation fault.
Could you tell me a solution

This my code:

Qt Code:
  1. MainWindow::MainWindow()
  2. {
  3. m_pView = QDeclarativeView(); // CONSTRUCT NEW QtDeclarativeView
  4. m_pView->setSource("qrc:/UI/main.qml");
  5.  
  6. setCentralWidget(m_pView);
  7. setFocus();
  8. centralWidget()->setFocus();
  9. }
  10.  
  11.  
  12. MainWindow::ChangeView()
  13. {
  14.  
  15. QDeclarativeView* pOldView = m_pView;
  16.  
  17. m_pView = QDeclarativeView();
  18. m_pView->setSource("qrc:/UI/main.qml");
  19.  
  20. setCentralWidget(m_pView);
  21. setFocus();
  22. centralWidget()->setFocus();
  23.  
  24. delete pOldView; // DESTROY THE POINTER; EXCEPTION HERE
  25. }
  26.  
  27. main()
  28. {
  29. MainWindow w;
  30.  
  31. w.show();
  32.  
  33. w.ChangeView();
  34. }
To copy to clipboard, switch view to plain text mode