Hello,
Lets set this:
using namespace srps;
bool SRPSMain::initialize()
{
Species * sp = qobject_cast<Species*>( obj );
sp->setObjectName("sp");
qDebug() << obj << sp;
connect( sp, SIGNAL(destroyed()), this, SLOT(deleted()) );
sp->deleteLater();
return true;
}
void SRPSMain::deleted()
{
qDebug() << Q_FUNC_INFO << sender() << qobject_cast<Species*>( sender() );
}
using namespace srps;
bool SRPSMain::initialize()
{
QObject * obj = new Species;
Species * sp = qobject_cast<Species*>( obj );
sp->setObjectName("sp");
qDebug() << obj << sp;
connect( sp, SIGNAL(destroyed()), this, SLOT(deleted()) );
sp->deleteLater();
return true;
}
void SRPSMain::deleted()
{
qDebug() << Q_FUNC_INFO << sender() << qobject_cast<Species*>( sender() );
}
To copy to clipboard, switch view to plain text mode
both classes are QObject direct subclases and have Q_OBJECT macro.
the output is:
srps::Species(0x82ab00, name = "sp") srps::Species(0x82ab00, name = "sp")
void srps
::SRPSMain::deleted() QObject(0x82ab00, name
= "sp") QObject(0x0
)
srps::Species(0x82ab00, name = "sp") srps::Species(0x82ab00, name = "sp")
void srps::SRPSMain::deleted() QObject(0x82ab00, name = "sp") QObject(0x0)
To copy to clipboard, switch view to plain text mode
so, why the second qobject_cast does not work?
Thanks.
Bookmarks