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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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 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?

        mrjjM 1 Reply Last reply
        0
        • B BoGut

          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?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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 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?

              mrjjM JonBJ 2 Replies Last reply
              0
              • B BoGut

                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?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on 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

                  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?

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 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 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 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

                      • Login

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