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 represent contents of Qvector
Forum Updated to NodeBB v4.3 + New Features

how to represent contents of Qvector

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 768 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.
  • J Offline
    J Offline
    jamesmfarrow
    wrote on last edited by jamesmfarrow
    #1

    Hello everyone, I have a struct of Qstrings(name age address) stored in a QVector and would like to show each name in a box/container/widget alphabetically top to bottom. Then be able click on a name and the additional info is then shown. Which is the best way to do this?

    Thanks James

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

      Hi,

      Sounds rather like a job for a small SQLite database.

      In any case, you can:

      • Create a QAbstractTableModel on top of your vector
      • Use a QDataWidgetMapper to show the relevent fields in a custom widget like shown in this example.

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

        Thanks! I will read up on the example shown. Trying to do a really simple contacts app. Thought I could use the vector of structs for the data...

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

          Then start directly with the database. It's clearly a better container and long term storage for that kind of data.

          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
          • J Offline
            J Offline
            jamesmfarrow
            wrote on last edited by
            #5

            Thanks! I am trying to learn Qt and C++ - this project is an exercise so I can get a feel for Qt and using widgets layouts buttons etc. I won't be using it anger... That is the reason I am using a vector - it will only store maybe a 10 -12 items at most to check the other functionality I am trying to write.

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

              Then building a model on top of it will also be an interesting exercice.

              What you can do is to create your version with vector plus model on top and once you have that working, move to a database and you'll see that the change needed should be minimal.

              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
              • J jamesmfarrow

                Thanks! I am trying to learn Qt and C++ - this project is an exercise so I can get a feel for Qt and using widgets layouts buttons etc. I won't be using it anger... That is the reason I am using a vector - it will only store maybe a 10 -12 items at most to check the other functionality I am trying to write.

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

                @jamesmfarrow
                If you implement the QAbstractTableModel approach, you will also find that you can present a data grid of the rows & columns in your data for free, by just putting a QTableView on to view it :)

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jamesmfarrow
                  wrote on last edited by
                  #8

                  Thanks everyone. I will read up on the examples that you have listed and see what I can come up with. No doubt I will be back when I get stuck :)

                  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