Results 1 to 4 of 4

Thread: How QDeclarativeView destruction

  1. #1
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default How QDeclarativeView destruction

    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 

  2. #2
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: How QDeclarativeView destruction

    The source code doesn't clear because you do not use new operator to instantiate the object, but you try to destroy using delete operator.
    ~ We are nothing in this universe ~

  3. #3
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How QDeclarativeView destruction

    Quote Originally Posted by viulskiez View Post
    The source code doesn't clear because you do not use new operator to instantiate the object, but you try to destroy using delete operator.
    Yes, it's my mistake. The source should be:

    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. m_pView = new QDeclarativeView(); // CONSTRUCT NEW QtDeclarativeView
    4. m_pView->setSource("qrc:/UI/main.qml");
    5.  
    6. setCentralWidget(m_pView);
    7. setFocus();
    8. centralWidget()->setFocus();
    9. }
    To copy to clipboard, switch view to plain text mode 

    But I can't not delete QDeclarativeView* after using new operator.
    It's ok to continue the program without delete, but it can lead to memory leaking. How to avoid it

  4. #4
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: How QDeclarativeView destruction

    Maybe the pOldView still used by another objects, so simply use QObject::deleteLater.
    Qt Code:
    1. pOldView->deleteLater();
    To copy to clipboard, switch view to plain text mode 
    ~ We are nothing in this universe ~

Similar Threads

  1. Drag into a QDeclarativeView
    By frankiefrank in forum Qt Quick
    Replies: 1
    Last Post: 3rd October 2011, 12:12
  2. Replies: 0
    Last Post: 3rd September 2011, 18:04
  3. Resize QDeclarativeView
    By Globulus in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2011, 17:31
  4. Replies: 2
    Last Post: 16th July 2011, 12:39
  5. Using QDeclarativeView::Show()
    By proj_symbian in forum Qt Quick
    Replies: 17
    Last Post: 30th May 2011, 19:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.