Hi,

first of all, sorry for my bad English.
Now the question.

I've written a class inherited from QThread
Qt Code:
  1. // DataSender.cpp
  2.  
  3. DataSender::DataSender(QObject *parent) : QThread(parent)
  4. {
  5. this->m_sendTimer.setInterval (0);
  6.  
  7. connect (&m_sendTimer, SIGNAL(timeout()), this, SLOT(sendData()));
  8. }
  9.  
  10. void DataSender::setSendInterval (int msec)
  11. {
  12. this->m_sendTimer.setInterval (msec);
  13. }
  14.  
  15. void DataSender::run ()
  16. {
  17. bool ans = true;
  18.  
  19. qDebug ("%s Started", qPrintable(this->objectName ()));
  20.  
  21. if (ans && this->m_sendTimer.interval () > 0) {
  22. this->m_sendTimer.start ();
  23. qDebug ("%s: Timer Started", qPrintable(this->objectName ()));
  24. }
  25.  
  26. if (ans) {
  27. this->exec ();
  28. }
  29.  
  30. this->m_sendTimer.stop ();
  31.  
  32. qDebug ("%s Stopped", qPrintable(this->objectName ()));
  33. }
To copy to clipboard, switch view to plain text mode 

This class is in a library.

When I use it in a GUI Application it works
Qt Code:
  1. void MainWindow::startSenders ()
  2. {
  3. DataSender* s = 0;
  4. for (int i = 0; i < DATA_TYPE_SIZE; ++i) {
  5. s = &this->m_senders[i];
  6. s->setSendInterval (10000);
  7. s->sender->start ();
  8. }
  9. qDebug ("Senders Started");
  10. }
To copy to clipboard, switch view to plain text mode 

but when I use it in a non-GUI application
Qt Code:
  1. // Main.cpp
  2. ...
  3. DataSender* senders[2];
  4.  
  5. senders[0] = new DataSender;
  6. senders[0]->setSendInterval(1000);
  7.  
  8. senders[1] = new DataSender;
  9. senders[1]->setSendInterval(5000);
  10.  
  11. qDebug ("RUNNING...");
  12.  
  13. for (int i = 0; i < 2; ++i) {
  14. senders[i]->start ();
  15. }
  16. result = app.exec ();
  17. ...
To copy to clipboard, switch view to plain text mode 
the slot connected to the timeout() signal of timer is never called.
The debug messages in DataSender.cpp at line 19 and 23 are printed; that means the thread is correctly started.

Any suggestion?