QML call function in C++ with threads
-
@jsulm Pulling code from moc output I happen to have lying around:
For a signal
void stuffChanged(QString)
, moc generates:// SIGNAL 0 void Singleton::stuffChanged(QString _t1) { void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) }; QMetaObject::activate(this, &staticMetaObject, 0, _a); }
QMetaObject::activate() is a private API in qtbase/src/corelib/kernel/qobject.cpp. The version that takes a pointer to the static meta object eventually calls this one:
void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_index, void **argv) { ... if ((c->connectionType == Qt::AutoConnection && !receiverInSameThread) || (c->connectionType == Qt::QueuedConnection)) { queued_activate(sender, signal_index, c, argv ? argv : empty_argv, locker); continue; ... }
The full source is a little lengthy to quote here, but check it out if you're curious. Also, you can trace the emission of a signal through to the call of a slot for an object in the same thread without a return to the event loop with the debugger.
To reiterate, signal emission is done when
emit signal()
returns. Calling of a particular slot may be pending for any queued connection. -
I agree, this while() was bothering me.
I'm using a _timer with QTimer where start() by clicking, I get the Socket data with onReadyRead() process met _timer.stop() but emito sign for the status, seems to be working well.
But I accept suggestions for improvement, but I removed the loop while()