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. QAbstractItemModel item identification from ModelIndex
Forum Updated to NodeBB v4.3 + New Features

QAbstractItemModel item identification from ModelIndex

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmodelindexqtreeview
4 Posts 2 Posters 1.3k 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.
  • P Offline
    P Offline
    poty
    wrote on 6 Mar 2018, 17:28 last edited by
    #1

    Hi!

    I need a QTreeView with a model referring to existing data(using C++).

    The data is a tree, using raw pointers in its nodes. I can reach any node by a custom unique ID.

    If I understand the paradigm correctly, my model have to implement functions like 'parent' in which I need to tell the parent item's ModelIndex from the ModelIndex of the child. I can do this by storing the data tree pointers in ModelIndex. This can be unsafe in my case. Is there any other option to handle this correctly?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Mar 2018, 20:38 last edited by SGaist 3 Oct 2018, 22:23
      #2

      HI and welcome to devnet,

      Why is it unsafe in your case ?

      Did you already saw the Simple Tree Model example in Qt's documentation ?

      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
      • P Offline
        P Offline
        poty
        wrote on 10 Mar 2018, 13:25 last edited by
        #3

        Hi! Thanks for the answer

        I think it is unsafe beacause my data tree can change by other mechanisms.
        I don't think that keeping pointers to dynamically changing data is a good idea in general.

        I've tried it( because I had no better idea) and now I have some new problem. I will post them to another topic.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Mar 2018, 22:24 last edited by
          #4

          Then you have to propagate the information when your underlying data changes.

          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
          0

          1/4

          6 Mar 2018, 17:28

          • Login

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