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. How to convert QHash into model data?
Forum Updated to NodeBB v4.3 + New Features

How to convert QHash into model data?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 569 Views 3 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.
  • N Offline
    N Offline
    npatil15
    wrote on last edited by
    #1

    Hello All,

    Every time I'm facing this issue when I want to have list of different data in hierarchy way.
    Example: QHash<QString, QHash<QString, QList<s_data>>> data;

    struct s_data
        {
            QString _d;
            QString _q;
            int _c;
        };
    QHash<QString, QHash<QString, QList<s_data>>> data;
    

    For this above, I want to have data in model-like, QStandardItemModel, or any other model which is easy to use.

    Please provide your suggestion and need a sample example of it, how I can convert such type of data into a model.

    Thanks.

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

      Hi,

      The first question is:what exactly do you want to show.in your view ?

      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
      • N Offline
        N Offline
        npatil15
        wrote on last edited by npatil15
        #3

        I'm not interested in the view, I just want a model, where I can store data and can retrieve it in a proper manner for further processing. It's just like a data storing in variable and then keep it open for further processing but in model way.

        I'm not sure does this possible or good way for this, whatever I understood from a model, where we can store data and it's fast and easy to retrieve data.

        JonBJ mrjjM 3 Replies Last reply
        0
        • N npatil15

          I'm not interested in the view, I just want a model, where I can store data and can retrieve it in a proper manner for further processing. It's just like a data storing in variable and then keep it open for further processing but in model way.

          I'm not sure does this possible or good way for this, whatever I understood from a model, where we can store data and it's fast and easy to retrieve data.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @npatil15
          Qt models are two-dimensional row/column indexed. Presumably at some level your outer QHash might be the rows and the inner QHash be the columns. The inner QList would be the data.

          However, I'll just throw this out there. Ready to be shot down, but ISTM a row/column model will not mesh well with QHashs. So far as I can see, Qt QHash does not even offer an option to access its elements via an index number, only via a key, which for you is QString. And QHash elements are not ordered, you cannot "insert at element 10", etc. Although there will be some way of manipulating it suitably for numeric indexes, I'm thinking it would not work well....

          1 Reply Last reply
          3
          • N npatil15

            I'm not interested in the view, I just want a model, where I can store data and can retrieve it in a proper manner for further processing. It's just like a data storing in variable and then keep it open for further processing but in model way.

            I'm not sure does this possible or good way for this, whatever I understood from a model, where we can store data and it's fast and easy to retrieve data.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @npatil15
            Hi
            Just as a note.
            If you are not planning on using any views with the model im not sure its worth it since you would then read your
            data using QModelIndexes and have to maintain working indexes across add/edit/delete.

            1 Reply Last reply
            1
            • N npatil15

              I'm not interested in the view, I just want a model, where I can store data and can retrieve it in a proper manner for further processing. It's just like a data storing in variable and then keep it open for further processing but in model way.

              I'm not sure does this possible or good way for this, whatever I understood from a model, where we can store data and it's fast and easy to retrieve data.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @npatil15
              As @mrjj has written, if you're not interested in using Qt views you probably don't want to go down the QAbstractModel route. Your data organisation does not mesh well with Qt's models' rows/columns, so don't bother forcing a square peg into a round hole.

              There is nothing magic or set-in-stone about Qt's models, or for that matter views. It's just an implementation of good practice for managing data and keeping the data manipulation separate from the presentation.

              So use Qt's model methods as an inspiration for what you might provide. Your outer QHash might be like rows, and the inner QHash like columns. But unlike Qt models, yours will be indexed by (QString, QString) instead of (int, int). If you do want views, you can invent your own signals & slots like Qt models-views have, but passing around QStrings as arguments instead of ints.

              For your "fast and easy to retrieve data", nothing will be faster/easier than sticking with QStrings as indexes instead of ints.

              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