Results 1 to 12 of 12

Thread: [SOLVED] How can I tell qtcreator to pass parent object to promoted class?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [SOLVED] How can I tell qtcreator to pass parent object to promoted class?

    [edit]
    Please ignore, this has been "solved". The problem wasn't qtcreator, it was my stupidity! Although the parent isn't explicitly set at the point of instantiation, it is set when calling addWidget, which eventually makes its way to the addChildWidget method in http://qt.gitorious.org/qt/qt/blobs/...el/qlayout.cpp

    Maybe I was casting incorrectly, which may explain why it wasn't working before, but it seems fine now. Sorry for wasting your time.

    Hi,

    I'm using QtCreator to build the UI for my project. I've got a QStackedWidget object in my mainwindow and each "layer", or "page", of the stacked widget has been promoted to a custom class, derived from QWidget. Note, I've also done something similar for a wizard in my project, where each wizard page has been promoted to a custom class.

    The problem is, although the classes are derived from QWidget (and qtcreator knows this), the generated code isn't passing a parent into the constructor of the promoted class on instantiation. It's not even using the setParent method after instantiation.

    If I understand correctly (I'm a C++ newbie, feel free to correct me), it means that I will have a memory leak because I'm not deleting these objects and they don't have a parent and thus won't be deleted automatically either. It also means I can't get a reference to the parent object.

    I know I could find a pointer or reference to my objects and manually call setParent, but is there any automated way of telling qtcreator to pass a parent object on instantiation (or at least call the setParent method after instantiation on objects that are derived from QObject)?

    Thanks!
    Last edited by stevebakh; 14th March 2010 at 20:19. Reason: Solved... there was no problem, just my own stupidity.

Similar Threads

  1. ActiveQt: How to pass image to ActiveX object?
    By AndreasSchlempp in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2009, 12:44
  2. Accessing a class Object by pointer in another class
    By pdoria in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2008, 15:59
  3. Replies: 3
    Last Post: 16th May 2007, 11:07
  4. How to pass a QString to another class ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th December 2006, 20:16
  5. object instantiation
    By drkbkr in forum Qt Programming
    Replies: 7
    Last Post: 29th June 2006, 02:26

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.