Results 1 to 4 of 4

Thread: Get Childs from a Widget in a inherited class

  1. #1
    Join Date
    Apr 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Get Childs from a Widget in a inherited class

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Get Childs from a Widget in a inherited class

    Can we see the code for MsgUser? It must inherit QObject. But with a small example your could help better.

  3. #3
    Join Date
    Apr 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get Childs from a Widget in a inherited class

    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!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Get Childs from a Widget in a inherited class

    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
    Qt Code:
    1. QObjectList getChildren() = 0;
    To copy to clipboard, switch view to plain text mode 
    and then you have to implement it in your "QObject"-child-classes.

Similar Threads

  1. Abstract base class and inherited class members
    By JovianGhost in forum General Programming
    Replies: 3
    Last Post: 19th March 2010, 12:32
  2. QStandardItemModel, parents and childs
    By alexandernst in forum Newbie
    Replies: 7
    Last Post: 23rd July 2009, 00:00
  3. Paint over childs
    By SABROG in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2009, 12:34
  4. Delete Layout and its childs
    By jano_alex_es in forum Newbie
    Replies: 1
    Last Post: 8th May 2009, 12:23
  5. Replies: 4
    Last Post: 19th March 2008, 17:47

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.