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. QList<QObject*> testList, how to access individual QObject.at() values?

QList<QObject*> testList, how to access individual QObject.at() values?

Scheduled Pinned Locked Moved Solved General and Desktop
qdebugqmlqlistqobject
11 Posts 4 Posters 2.0k Views
  • 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 29 Jul 2020, 18:08 last edited by
    #2

    Hi and welcome to devnet,

    What exact value do you want to get ?

    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
    3
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 29 Jul 2020, 18:17 last edited by
      #3

      Hi
      Normally you would do like
      qDebug() << *test01;

      But qDebug() cannot output the properties of a QObject so it will just
      not compile.

      so you can do

      qDebug() << test01->SomeVar << " " << test01->SomeOtherVar;

      But as @SGaist asks:
      what did you expect it to output ?

      1 Reply Last reply
      4
      • B Offline
        B Offline
        BoGut
        wrote on 29 Jul 2020, 18:31 last edited by
        #4

        Hello, thanks for the quick replies. I'm trying to access the text string for each element. So if I'm understanding correctly, QObject will always show address data? Does list.value(0) for example not contain data at that location element? Not pointer address data, actual text data?

        M 1 Reply Last reply 29 Jul 2020, 18:33
        0
        • B BoGut
          29 Jul 2020, 18:31

          Hello, thanks for the quick replies. I'm trying to access the text string for each element. So if I'm understanding correctly, QObject will always show address data? Does list.value(0) for example not contain data at that location element? Not pointer address data, actual text data?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 29 Jul 2020, 18:33 last edited by
          #5

          @BoGut
          Hi
          Its a live binary object so you store a pointer to it in the list.
          So when QDebug see that pointer, it will just print out the address as
          not much else it can do.
          You can also print out elements of the QObject but you have to tell
          qDebug() which ones.

          1 Reply Last reply
          2
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 29 Jul 2020, 18:33 last edited by
            #6

            What text string ?
            QObject cannot be copied hence you have a list of pointers to QObject instances.

            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
            3
            • B Offline
              B Offline
              BoGut
              wrote on 29 Jul 2020, 18:57 last edited by
              #7

              Ok this is starting to make sense now, somewhat :-)
              When I do a print out of the QList<QObject*> list, I get now this: membersList(0x282a4d000b0). I checked and membersList is defined as MembersList* members() const. So can I just do a qDebug() << members()[list.value(index)] to get the value stored?

              M J 2 Replies Last reply 29 Jul 2020, 19:02
              0
              • B BoGut
                29 Jul 2020, 18:57

                Ok this is starting to make sense now, somewhat :-)
                When I do a print out of the QList<QObject*> list, I get now this: membersList(0x282a4d000b0). I checked and membersList is defined as MembersList* members() const. So can I just do a qDebug() << members()[list.value(index)] to get the value stored?

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 29 Jul 2020, 19:02 last edited by
                #8

                @BoGut
                Hi
                Im not sure what MemeberList is..
                In any case, you can print out Properties via the meta system
                see here how
                https://stackoverflow.com/questions/36518686/dump-all-properties-of-a-qobject-derived-object

                1 Reply Last reply
                1
                • B BoGut
                  29 Jul 2020, 18:57

                  Ok this is starting to make sense now, somewhat :-)
                  When I do a print out of the QList<QObject*> list, I get now this: membersList(0x282a4d000b0). I checked and membersList is defined as MembersList* members() const. So can I just do a qDebug() << members()[list.value(index)] to get the value stored?

                  J Offline
                  J Offline
                  JonB
                  wrote on 29 Jul 2020, 19:15 last edited by JonB
                  #9

                  @BoGut
                  None of us are sure what you're trying to do or expect :) I will offer this, as a possibility; do you know what kind of object --- derived from QObject --- you expect the objects in the list to be? Such as your Member objects? You might want to look at qobject_cast if you want your code to try casting the generic QObject *s to a specific QObject derived-type, and on that you can call its dedicated methods if it is that type of object.

                  1 Reply Last reply
                  1
                  • B Offline
                    B Offline
                    BoGut
                    wrote on 29 Jul 2020, 20:26 last edited by
                    #10

                    I want to thank you all for the help, I'll look into using the qobject_cast code and I'll post an update when I finally fix it. Stay tuned.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      BoGut
                      wrote on 1 Aug 2020, 20:53 last edited by
                      #11

                      So it looks like I was missing the variable statement after this. It works now. Thanks everyone for the help.

                      QList<QObject*> list() const;
                      for (int index=0; index < list.size(); index++) {
                           QObject *test01 = list.value(0)->name();
                           qDebug() << test01;
                      }
                      
                      1 Reply Last reply
                      0

                      11/11

                      1 Aug 2020, 20:53

                      • Login

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