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. [SOLVED] Data Structure - QList<QString> vs other type
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Data Structure - QList<QString> vs other type

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

    Hey,

    I would like to keep a list of item that have been marked as "done"
    Real use case : When a workout is done, I would add it's name (unique) into a QList.
    The user interface would then show a different color for this workout (inside a QTableView with custom delegate).

    I was wondering if storing this inside a QList is a good idea? Does the method .contains(QString other) of QList takes a long time to return true or false? is it O(1)? The List will become large and I want to make sure to use the best data type possible.

    Thank you!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      QList::contains(QString other) has a linear complexity, which is O(n).
      I don't know any other way to find out if an item is in a list except to compare the items.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        archqt
        wrote on last edited by
        #3

        Hi,
        i guess each element is unique ? so maybe using a QSet<QString> is nice, as the search for an element is fast.
        Sincerely

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on last edited by
          #4

          QSet, Perfect!

          I was looking for a QHash that only has the key, this is exactly it.
          Thank you very much for the help guys.


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maximus
            wrote on last edited by
            #5

            Yes each workout name is unique, I guess QHash<QString, bool> is the same thing as QSet?

            Here is a concrete example of the "workout list":
            "https://www.dropbox.com/s/1s922cma69jae33/workoutlst.png?dl=0":https://www.dropbox.com/s/1s922cma69jae33/workoutlst.png?dl=0

            Now, another question if you guys had experience with this...
            I'm thinking of the best way to save the QHash in memory too keep the list persistent. I was thinking maybe a field in the database where I save all the name separated by a delimiter ("workout1;workout2;...). The downside I can see is it will become a big list, so saving and loading this field each session would be long.

            Another option: Save it with QSettings locally but then if you change computer you would loose your list. Not sure if this idea is crazy or not: could saving the QSettings file as .ini in the database be a possible solution? Instead of saving it locally it would be portable and you would keep all your settings on multiple computers. Just food for thoughts..
            Thanks for all the help!

            Update :
            Seems like storing a QList to a Text column in MySQL is a bad idea
            "http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad":http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad

            So I'm considering a table "Workout_Done" with columns : "id_user" and "name_workout"


            Free Indoor Cycling Software - https://maximumtrainer.com

            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