Results 1 to 4 of 4

Thread: why is the sender's type of the destroyed() signal QPushButtonPrivate?

  1. #1
    Join Date
    Mar 2011
    Posts
    25
    Thanks
    7
    Qt products
    Qt4

    Default why is the sender's type of the destroyed() signal QPushButtonPrivate?

    I have a delegate class that inherits from QStyledItemDelegate. In SlotDestroyed(): why is sender() of the type QPushButtonPrivate and not QPushButton?

    Qt Code:
    1. QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. QPushButton *btn = new QPushButton(parent);
    4. btn->setText("test");
    5.  
    6. connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(SlotDestroyed(QObject*)));
    7. return btn;
    8. }
    9.  
    10.  
    11. void Delegate::SlotDestroyed(QObject* editor)
    12. {
    13. QPushButton *btn = qobject_cast<QPushButton*>(sender()); // why null?
    14. QObject *s = sender();
    15. btn = reinterpret_cast<QPushButton*>(sender());
    16. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: why is the sender's type of the destroyed() signal QPushButtonPrivate?

    Probably because QPushButton is implemented in two parts, with an outer "public" class and an inner "private" one. Lots of Qt classes have this two-part implementation, for "security" reasons, to make it easier for object data to be shared, and to make object assignment simpler and lighter-weight.

    However, the behavior you've discovered is probably technically a bug.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: why is the sender's type of the destroyed() signal QPushButtonPrivate?

    Out of interest, how are you going to use a pointer to an object that is advertising its imminent demise?

  4. #4
    Join Date
    Mar 2011
    Posts
    25
    Thanks
    7
    Qt products
    Qt4

    Default Re: why is the sender's type of the destroyed() signal QPushButtonPrivate?

    To release some resources (which I'm doing in the destructor now). I was just wondering if that's a bug or if there is a reason for that behavior.

Similar Threads

  1. Replies: 0
    Last Post: 15th December 2010, 06:18
  2. Replies: 3
    Last Post: 30th July 2010, 16:34
  3. use user type in signal function parametrs
    By sergey_85 in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2009, 11:18
  4. [solved] Which object type is QObject::sender()?
    By ricardo in forum Qt Programming
    Replies: 6
    Last Post: 8th May 2009, 21:03
  5. How Signal/slot is type-safe????
    By Shuchi Agrawal in forum Newbie
    Replies: 6
    Last Post: 10th March 2007, 04:59

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.