QList<QObject*> testList, how to access individual QObject.at() values?
-
Hi and welcome to devnet,
What exact value do you want to get ?
-
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 ? -
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?
-
@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. -
What text string ?
QObject cannot be copied hence you have a list of pointers to QObject instances. -
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? -
@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 -
@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 fromQObject
--- you expect the objects in the list to be? Such as yourMember
objects? You might want to look at qobject_cast if you want your code to try casting the genericQObject *
s to a specificQObject
derived-type, and on that you can call its dedicated methods if it is that type of object. -