Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom model system - error when replacing root item, no debug info :- (
Forum Updated to NodeBB v4.3 + New Features

Custom model system - error when replacing root item, no debug info :- (

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 427 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by Dariusz
    #1

    Hey

    This is a little tricky, as I'm quite limited in what source I can post and the fact that entire qabstractitemmodel/item/etc were written and no standard qt model objects are used...

    In any case, the setup is as follows:

    QTreeView>QSortFilterProxyModel>QIdentityProxyModel>QAbstractItemModel.

    I have a case where I want to display 2 qtreeviews, and display content of item from TreeA in treeB.
    I have "2" models. modelA for treeA, this one remains unchanged. modelB I replace this model rootItem all the time - this is where error "happens"?
    Each treeItem, has a "childModel" - item, that contain its own data. Kinda dual data structure. Essentially

    class treeItem: {
        treeItem *modelItem; // << this is another item inside this item
        inline treeItem*getChildModel(){return modelItem;}
    }
    

    The idea is, whenever I click on any of items in treeA, I get its item->getChildModel item and I set that as a root item on modelB. By replacing rootItem I replace entire data structure in modelB thus I can quickly change data? I think...

    In any case, this works, if I click on any item on treeA, treeB content changes - all great. The problems starts if for example... I edit text in treeB, it changes as it should and data appear to be "updated". But here is the kicker... when I change item in treeA
    It now broke down and I can't change items in treeA anymore... just by running test in VS instead of qtCreator.

    In any case I have a sea of Qt5Cored.dll/Qt5Widgetsd.dll errors and no symbols loaded from xxx...

    Maybe I need to emit a signal before changing rootItem in my modelB ?

    How can I fix that? I'm lost :- (


    Yep it feels like its down to replacing the root item of tree model and I guess qt crashes in the thread or something like that when he loses root item. Perhaps I should mutex it...mhmm


    Soo it seems that QMutex & and it works ?...mhmmmm Feels like I could us a signal that would tell Qt that I'm about to mess with model root...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You have written one very important word: thread. If you are using threads then access to all resources that can be accessed from multiple threads must be protected. Qt won't do that for you, it's your responsibility.

      As for signalling you are about to modify your model, take a look at the various beginXXX/endXXX methods in QAbstractItemModel. In your case, beginReset/endReset are likely the pair you are looking for. Note that these methods don't replace proper access protection when using multiple threads.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        Hey

        Well I didnt start multiple threads, I think they are being run/managed by Qt. I recon that while QTreeView::DrawRows was being run & I change root item in my model, then that caused error & crash. I did look at begin/end. Just did not find any that sounded like... aboutToChangeRootItem or something like that. I found one "private" signal but I had no idea what to do with it.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          As I suggested, beginResetModel and endResetModel are what you are looking for. it's what usually goes with "i'm going to nuke everything".

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved