在10-20个信号调用之一中,我在插槽中有一个无效参数。问题归结为以下
class Sender : public QEnabledSharedFromThis<Sender>
{
public:
void emitSignal()
{
emit someSignal(sharedFromThis())
}
signals:
someSignal(const QSharedPointer<Sender>&);
int m_i;
};
qRegisterMetaType<QSharedPointer<Sender>>();
Sender sender;
class Receiver
{
Receiver()
{
connect(&sender, &Sender::emitSignal, this, [this](const QSharedPointer<Sender>& sender) {
// Crash here.
// 'sender' argument seems invalid (dangling reference)
qDebug() << sender->m_i;
})
}
};
当发生这种情况时,我可以在QCoreApplication::notifyInternal2
(例如)中的崩溃转储中看到:
event->nargs == 2 // ok
event->type[0] == 0 // ok
event->type[1] == some reasonable value like 1105
event->sender is alive and seems correctly initialized
但event->args
似乎无效。
event->args[0] != 0
(Sender*)(args[1]) is full of 'can't read memory'
平台是Win64,qt版本是5.6.1,编译器是vs2015。发布。 有什么想法吗?感谢。