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. Linked list, but not like that
Forum Updated to NodeBB v4.3 + New Features

Linked list, but not like that

Scheduled Pinned Locked Moved General and Desktop
12 Posts 6 Posters 3.8k 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
    MarkRS
    wrote on 8 Feb 2013, 15:35 last edited by
    #1

    I want to use a linked list structure to link structures in multiple ways.

    The structures are loaded from a(n XML) file, and simply allocated in the order they are loaded.
    Each structure may then belong to various lists as specified by tags in the XML.

    I'm imagining each structure having an array of link structures, one element for each list it is a part of.

    Is there something like this in Qt or am I in a "roll your own" situation?
    I've hunted around and not found anything so I'm guessing it's the latter, but I thought I'd ask, just in case.

    M

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tzander
      wrote on 11 Feb 2013, 11:31 last edited by
      #2

      Sounds like you want a very flexible solution if you want to define your datastructure like that in XML.
      I think you are clearly in the 'write it yourself' catagory ;)

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on 11 Feb 2013, 11:42 last edited by
        #3

        Is your XML linear or a tree-like structure? You can easily build trees by deriving from QObject, which is one of the most basic building blocks of Qt.

        If it is a linear structure with objects of different type, it is still a good idea to make your classes hierarchy QObject derived, store a QList of pointers to the actual instances and use polymorphism to traverse the list. The linked list is somewhat slower, and only makes sense to use if you have a lot of inserting in the middle, which you won't have since you will be parsing an XML.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MarkRS
          wrote on 11 Feb 2013, 17:52 last edited by
          #4

          Thanks both.

          utcenter is right on the money. Of course (doh!) I just let it build one list and then set up lists (in the same pass) using pointers to the existing structures. I was getting all overcomplicated in my head :(

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on 11 Feb 2013, 22:54 last edited by
            #5

            Keep in mind QObject has its copy constructor disabled because you shouldn't really copy a QObject, so you are pretty much forced to put pointers to QObjects in the actual list.

            But you may not need to derive from QObject, it is useful for object lifetime and memory management and for signals and slots, but you could go away with something cheaper and lighter.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on 12 Feb 2013, 07:49 last edited by
              #6

              QObject might also be too heavy if you do not need its special features like signals/slots, etc.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tzander
                wrote on 12 Feb 2013, 10:53 last edited by
                #7

                As a rule of thumb I'd say that a collection of a 1000 items or less, the QObject overhead is not all that relevant. That amount goes down a bit when you are in very memory restricted environment (like an embedded device).
                So, while I agree with Tobias it might be too heavy, for many usages its Ok.

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  utcenter
                  wrote on 12 Feb 2013, 11:55 last edited by
                  #8

                  I never really checked how big QObject actually is. The private dynamically allocated data that is, according to sizeof it is fairly compact, but it doesn't catch everything.

                  Anyway it is pretty straightforward to implement a custom tree structure, only two members are really needed - the parent node and a list of children nodes. It can even be brought down further, if the hierarchy is only one way the parent node can be removed while preserving the ability to traverse the tree recursively, but having the children being unaware of the parent has its limitations.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on 12 Feb 2013, 12:11 last edited by
                    #9

                    Or, you just take one of the already available alternatives. I have used "this one":http://tree.phi-sci.com/ successfully in the past.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MarkRS
                      wrote on 4 Jun 2013, 19:57 last edited by
                      #10

                      Ok, it's been a while, sorry.
                      I understand, at least in principle, the different types of structures, however that's not the issue.

                      They key phrase in the initial question was "in multiple ways".
                      I want to build one set of data and then thread the items through multiple lists.

                      It's actually for displaying a list of musical instruments.
                      The list should be switchable to display different groups of instruments; for example, orchestral instruments, jazz instruments, brass band, &tc &tc.
                      Each instrument may (!) be on many different lists.

                      Each instrument needs quite a large structure so I really only want one instance for each instrument.

                      At this point I'm thinking I will build multiple qlists of pointers to my instrument data structures.
                      Any thoughts?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 4 Jun 2013, 20:10 last edited by
                        #11

                        Hi,

                        Have you given a thought about the model/view paradigm ? Sounds like you have a set of instruments which would be your model data and over that you'll have proxy models to sort/filter your instruments (then no need to modify the model data) and the views (probably custom) to show what you want.

                        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
                        • M Offline
                          M Offline
                          MarkRS
                          wrote on 4 Jun 2013, 21:14 last edited by
                          #12

                          No, I hadn't thought of model/view for this.
                          I'm contributing to a (largish) piece of open source s/w, and this is a very small part of it. I think I'd make a big splash in the existing code by implementing something like that... I'll have a look, though. Thanks.

                          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