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. Can one easily convert between QVariantMap and ItemModel (QAbstractItemModel, say)?

Can one easily convert between QVariantMap and ItemModel (QAbstractItemModel, say)?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k 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.
  • shaveraS Offline
    shaveraS Offline
    shavera
    wrote on last edited by
    #1

    It really doesn't seem possible directly from what I've looked at so far... but it seems strange to me that on the one hand, you have this QVariantMap kind of structure that is useful for storing data and, say, transferring it into a JSON object of some kind. And on the other hand, there are QAbstractItemModel type structures that are useful for exposing the data to a GUI and allowing it to be edited and modified.

    Both of them have the capacity to be nested, tree-like structures... A data element in a QVariantMap can be a list, a list of lists (ie, an array) or another QVariantMap. Data Models are similarly nested, though they are addressed by row/column, parent/child relationships rather than named items.

    So I'm starting to roll my own class, a QVariantMapModel, to do just this... But I don't want to reinvent the wheel if I'm forgetting some easier way.

    The codebase for this project will be https://bitbucket.org/alex_shaver/qvariantmapmodel_project

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

      Hi,

      I haven't seen yet a model doing that so go ahead :)

      As for the coding style and guidelines you have "this":http://qt-project.org/wiki/Qt_Coding_Style and "this":http://qt-project.org/wiki/Coding-Conventions

      From your code base, the file casing should be lowercase. Only the generate includes are camel cased

      Happy coding !

      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
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Thanks for sharing!

        If you're interested, here's the work of another community member, who made a model for JSON documents: http://qt-project.org/forums/viewthread/51593/

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0

        • Login

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