Slot argument is (sometimes) invalid

105 views Asked by At

In one of like 10-20 signal invocations i have an invalid argument in the slot. The problem boils down to the following

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;
        })  
    }
};

When this happens I can see in the crash dump in QCoreApplication::notifyInternal2 (for example) that:

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

But event->args seems to be invalid.

event->args[0] != 0
(Sender*)(args[1]) is full of  'can't read memory'

Platform is Win64, qt version is 5.6.1, compiler is vs2015. Release. Any thoughts? Thanks.

0

There are 0 answers