PDA

View Full Version : Get Childs from a Widget in a inherited class



Roman
23rd April 2010, 10:08
Hi,

I've got an abstract class MsgUser. Every Widget in my MainWindow will be inherited from this class.
Now I need to access the Widget childs in the MsgUser class. Unfortunately I can't do this cause my MsgUser class do not have any childs so the compiler allways stops with an error, as the MsgUser has no function this->children().

Does someone know what I have to do in this case?

Thanks,
Roman

Lykurg
23rd April 2010, 10:29
Can we see the code for MsgUser? It must inherit QObject. But with a small example your could help better.

Roman
23rd April 2010, 10:41
Well the code is quit small by now: h-File:


class MsgUser{
private:
MsgHandler *MsgHdl;
Message *msg;
public:
virtual void MsgAnswer(Message *msg);
};


cpp-file:


void MsgUser::MsgAnswer(Message *msg)
{
QObjectList objects = this->children();
}


Well I know that in fact it should inherit QObject, but this is not an obtion since every Widget later on will inherit the MsgUser... so multiple inherit of QObject would be the problem!

Lykurg
23rd April 2010, 12:36
I don't know your architecture and I wonder if you really would have problems with multiple inherit. But anyway, you can use children() only if the class inherits QObject. So in you case make a pure virtual function like
QObjectList getChildren() = 0; and then you have to implement it in your "QObject"-child-classes.