Results 1 to 9 of 9

Thread: Creating a nested QAbstractListModel containing a QAbstractListModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a nested QAbstractListModel containing a QAbstractListModel

    That is also ok, but you need to make sure that the ownership of the pointer is clear.
    Either make sure that each model has a parent, or use QQmlEngine::setObjectOwnership() to use the ownership to C++ on the pointer before returning it.
    Could you elaborate more on how to achieve this?

    As currently, i'm using the invokable method to return the model. The model is updated when menu model has changed. After some changes the app crashes with the error "Second Chance Assertion Failed: File f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp, Line 52".

    This is caused by the problem you mentioned
    Otherwise QML will delete/garbage collect the model when it doesn't need it anymore and your C++ code might not like that
    Can you suggest how to handle this?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Creating a nested QAbstractListModel containing a QAbstractListModel

    As I said, use QQmlEngine::setObjectOwnership():
    Qt Code:
    1. MenuModel* MenuModel::subMenuModel(int index)
    2. {
    3. MenuModel *subMenu = m_menuItems.at(index)->subMenu();
    4. QQmlEngine::setObjectOwnership(subMenu, QQmlEngine::CppOwnership);
    5. return subMenu;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    volcano (11th March 2016)

  4. #3
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a nested QAbstractListModel containing a QAbstractListModel

    Thanks anda_skoa for all the advice and help, it really helped me.

Similar Threads

  1. QAbstractListModel
    By Archa4 in forum Newbie
    Replies: 9
    Last Post: 9th February 2011, 14:43
  2. Problem with QAbstractListModel
    By chandan in forum Newbie
    Replies: 0
    Last Post: 12th April 2010, 00:24
  3. QAbstractListModel problem
    By UltimatePace in forum Qt Programming
    Replies: 5
    Last Post: 27th September 2009, 10:51
  4. Problem with QAbstractListModel
    By eekhoorn12 in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2009, 14:26
  5. QAbstractListModel searching.
    By ComaWhite in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2009, 18:41

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.