PDA

View Full Version : why is the sender's type of the destroyed() signal QPushButtonPrivate?



iwatsu
19th April 2011, 22:13
I have a delegate class that inherits from QStyledItemDelegate. In SlotDestroyed(): why is sender() of the type QPushButtonPrivate and not QPushButton?



QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QPushButton *btn = new QPushButton(parent);
btn->setText("test");

connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(SlotDestroyed(QObject*)));
return btn;
}


void Delegate::SlotDestroyed(QObject* editor)
{
QPushButton *btn = qobject_cast<QPushButton*>(sender()); // why null?
QObject *s = sender();
btn = reinterpret_cast<QPushButton*>(sender());
}

DanH
20th April 2011, 03:06
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.

ChrisW67
20th April 2011, 07:02
Out of interest, how are you going to use a pointer to an object that is advertising its imminent demise?

iwatsu
20th April 2011, 15:42
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.