I am using signal/slot in a multithread stock trading system. Apart from the main GUI thread, I have a data feed API thread and a data processing thread. The data feed API thread monitors the market data and if data received, signals are emitted. The data processing thread has slots listen to the signals, and simply print the msg in signals. The signals are sent very frequent, about 100 signals per second. Currently, my slots only work for 1 to 2 minutes then stop response to signals if use default connection. If use directconnection, slots work normally, but in the same thread of data API, which is not I want. The followings are codes related to signal/slot communication. Please kindly help, thanks.

PosixIBClient::tickPrice( ) and tickSize() runs in data feed API thread

Qt Code:
  1. void PosixIBClient::tickPrice( TickerId tickerId, TickType field, double price, int canAutoExecute)
  2. {
  3. qDebug() << "PosixIBClient: tickString() in thread: " << QThread::currentThreadId();
  4. qDebug() << "tickPrice():" << tickerId <<", TickType:" << field << ", price:" << price;
  5.  
  6. emit DummySignalTicked(QString::number(tickerId));
  7. }
  8.  
  9. void PosixIBClient::tickSize( TickerId tickerId, TickType field, int size)
  10. {
  11. emit DummySignalTicked(QString::number(tickerId));
  12. }
To copy to clipboard, switch view to plain text mode 

TestSignalSlot - runs in data processing thread

Qt Code:
  1. #include <QObject>
  2. #include <QThread>
  3.  
  4. class TestSignalSlot : public QObject
  5. {
  6. Q_OBJECT
  7. public:
  8. explicit TestSignalSlot(QObject *parent = 0);
  9. virtual ~TestSignalSlot();
  10.  
  11. QThread *pThread;
  12. signals:
  13.  
  14. public slots:
  15. void onDummySignalTraded(const QString &msg);
  16. void onDummySignalTicked(const QString &msg);
  17. };
  18.  
  19. #endif // TESTSIGNALSLOT_H
To copy to clipboard, switch view to plain text mode 



Qt Code:
  1. #include "testsignalslot.h"
  2. #include <QDebug>
  3.  
  4. TestSignalSlot::TestSignalSlot(QObject *parent) : QObject(parent)
  5. {
  6. pThread = new QThread;
  7. pThread->start();
  8. moveToThread( pThread );
  9. }
  10. TestSignalSlot::~TestSignalSlot()
  11. {
  12. pThread->exit( 0 );
  13. pThread->wait();
  14. delete pThread;
  15. }
  16.  
  17. void TestSignalSlot::onDummySignalTraded(const QString &msg)
  18. {
  19. qDebug() << "TestSignalSlot::onDummySignalTraded():" << msg;
  20. }
  21.  
  22. void TestSignalSlot::onDummySignalTicked(const QString &msg)
  23. {
  24. qDebug() << "TestSignalSlot::onDummySignalTicked() in thread: " << QThread::currentThreadId();
  25. qDebug() << "TestSignalSlot::onDummySignalTicked():" << msg;
  26. }
To copy to clipboard, switch view to plain text mode 

The signal/slot connected as below:

Qt Code:
  1. connect(pPosixIBClient, SIGNAL(DummySignalTraded(const QString&)), pTestSignalSlot, SLOT(onDummySignalTraded(const QString&)));
  2. connect(pPosixIBClient, SIGNAL(DummySignalTicked(const QString&)), pTestSignalSlot, SLOT(onDummySignalTicked(const QString&)));
To copy to clipboard, switch view to plain text mode