[Interest] C++ signal to QDeclarativeItem slot through Connections()

Preet prismatic.project at gmail.com
Tue Mar 5 05:27:37 CET 2013


Hiya,

I have a QObject (c++) that sends a signal to the qml engine. A qml
Connections() element receives the signal and in turn calls a slot in a
custom QDeclarativeItem.

Everything is running in the same (main) thread. I thought that the above
scenario would behave like a direct connection; as if I was directly
invoking the QDeclarativeItem's slot through a function call. This doesn't
seem to be the case though. Instead, it looks like the c++ code just
returns immediately after emitting the signal:

QTimerElapsed m_timer;
m_timer.start();
...

void SomeQObject::someFunction
{
   qint64 time_before = m_timer.elapsed();
   emit signalReceivedByQmlEngine();
   qint64 time_after = m_timer.elapsed();
}

time_before always == time_after. If I time how long it takes for the
QDeclarativeItem's slot to complete, I see it takes several ms. I'm on
Linux, so timing resolution shouldn't be a problem... and just to be sure,
I repeated the timing tests with system timers as well [us resolution] with
the same results. SomeQObject::someFunction returns immediately, but the
QDeclarativeItem's slot takes a measurable amount of time to complete.

Could someone please explain the underlying behavior here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130304/d41854ed/attachment.html>


More information about the Interest mailing list