The Qt documentation says that returning signal values ββis not possible:
Signals are automatically generated by moc and should not be implemented in a .cpp file. They can never have return types (i.e. use void).
Related SO questions:
- Can Qt signals return a value?
- Qt: slot return value?
However, from my tests (Qt 4.8.1), I can say that the return values ββdo work:
- If the signal / slot is on the same thread, ConnectionType can be
Qt::AutoConnection - With a signal / slot in different threads, I need to use
Qt::BlockingQueuedConnection
So in my code I call a signal
QString dp = emit WscAircrafts::signalAircraftsJsonArray();
and the moc signal returns a QString ,
QString _t0; void *_a[] = { const_cast<void*>(reinterpret_cast<const void*>(&_t0)) }; QMetaObject::activate(this, &staticMetaObject, 0, _a); return _t0;
Here is the moc slot in which it returns a QString
case 4: { QString _r = _t->slotAircraftJsonArray(); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; } break;
All this seems pretty straightforward, so why is this a contradiction to the documentation? Where will the problem of using the return value be? As said, in my code this seems to work.
qt qt4 qt-signals
Horst walter
source share