Details
-
Bug
-
Resolution: Out of scope
-
P2: Important
-
4.6.2
-
None
Description
QSignalSpy enforces a Qt::DirectConnection, which makes a valid test case like below crash.
#include <QtGui> #include <QtTest/QtTest> class Emitter : public QObject { Q_OBJECT public: Emitter() { } void emitSignal() { emit signal(); } signals: void signal(); }; class MyThread : public QThread { Q_OBJECT public: MyThread(Emitter *emitter) : m_emitter(emitter) { } ~MyThread() { wait(100); } protected: void run() { for (int i = 0; i < 100; ++i) { m_emitter->emitSignal(); msleep(100); } } private: Emitter *m_emitter; }; #include "main.moc" int main( int argc, char *argv[] ) { QApplication app( argc, argv ); Emitter emitter; QSignalSpy spy(&emitter, SIGNAL(signal())); for (int t = 0; t < 5; ++t) { MyThread *thread = new MyThread(&emitter); thread->start(); QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); } QTest::qWait(20000); qDebug() << spy.count(); return 0; }