[Interest] Signal Slot Ordering (or Not)

Peter M. Groen peter at osdev.nl
Thu Apr 7 15:34:04 CEST 2016


In a simple setup ( One sender object with a signal, One receiver with
a slot, argument is sequence number, both objects running in a
single thread ) some unexpected behaviour (at least for me) is noticed.

The connect between the mentioned signal / slot is done with
Qt::DirectConnection. According to the documentation, each slot is
called directly. ( The slot is invoked immediately when the signal is
emitted. The slot is executed in the signalling thread. )

In a for-loop, I'm sending 10 signals directly in one burst, like so :

    for( int nCount = 0; nCount < number_of_signals; nCount++ )
    {
        std::cout << "[SignalSender::timerTimeOut] - "
                  << QString( "Signal Sending. Timer : %1, Run : %2,
    Sequence : %3" ) .arg( timer_interval_msecs )
                     .arg( run_number )
                     .arg( nCount ).toStdString() << std::endl;
        emit signalSendSequence( timer_interval_msecs, run_number,
    nCount ); QCoreApplication::processEvents();
    }

I'm expecting the output would be in ascending order, but every once in
a while, the output is all thrown together. That is quite unexpected,
based on the documentation.

Is this a bug, or by design?

Regards,

-- 
Open Systems Development
Peter M. Groen
Het Buitenwater 54
2235 TB  Valkenburg (ZH)
Mob : +31 6 811 0 3537
Email : peter at osdev.nl
Skype : peter_m_groen



More information about the Interest mailing list