Hi,
first of all my question may be seemed too open, but i think its not ,

i want to read from a electronic device (from serial port) every 50-100 msec and i think i must added it to a thread i call it main thread, i parse readed data and if i have a good result show some message in my ui,
i have a menu form in my ui too, if user click every of buttons in ui, my main thread must block.
so this is what i want: if main thread run Ui block and if ui run main thread block. i have some messaging mechanism with signals and slots too,

so i must use wait conditions or you have another suggestions?? what you say?

my main thread each loop get only 1 second time for run and then can sleep 50 msec or set/release a wait conditon i dont know
i have another thread too if another two threads are block, and if its time of my tasks (like 2 times in hour) for downloading and uploading my results, this one must run but dont block their, priority of those is more than this thread and i must send this thread to sleep,
on another hand this thread only have 50-100 msec to run and then must go to sleep until main thread finish one loop work and go to sleep.
but downloading and uploading can run like that????

and my another question about this thread, how this one must be implemment? i mean use same mechanism probably but i must use a event loop for this thread am i right?
this is my download command

Qt Code:
  1. class DownloadCommand : public ICommand
  2. {
  3. Q_OBJECT
  4. public:
  5. DownloadCommand(QObject *parent = 0);
  6. DownloadCommand(const QString& url, QObject* parent=0);
  7.  
  8. void setUrl(const QString& url) { m_url = QUrl(url); }
  9.  
  10. signals:
  11.  
  12. public slots:
  13. void onNetworkReply(QNetworkReply* reply);
  14. void downloadCompleted(qint64 d, qint64 size);
  15. QString execute();
  16.  
  17. private:
  18. QUrl m_url;
  19. QString m_localpath;
  20. QNetworkAccessManager manager;
  21. QNetworkReply* m_reply;
  22. };
  23.  
  24. DownloadCommand::DownloadCommand(QObject *parent) :
  25. ICommand(parent)
  26. {
  27. }
  28.  
  29. DownloadCommand::DownloadCommand(const QString &url, QObject *parent) : ICommand(parent)
  30. {
  31. m_url = QUrl::fromUserInput(url);
  32. }
  33.  
  34. QString DownloadCommand::execute()
  35. {
  36. m_reply = manager.get(QNetworkRequest(m_url));
  37. connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onNetworkReply(QNetworkReply*)));
  38. connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadCompleted(qint64,qint64)));
  39. return tr("Download Started...");
  40. }
  41.  
  42. void DownloadCommand::onNetworkReply(QNetworkReply *reply)
  43. {
  44. if(reply->error() != QNetworkReply::NoError)
  45. return;
  46.  
  47. QByteArray data = reply->readAll();
  48. if(data.length() < 2) return;
  49.  
  50. QFileInfo fileInfo(m_url.path());
  51. QString fileName = fileInfo.fileName();
  52. if(fileName.isEmpty())
  53. fileName = "unknown.file";
  54.  
  55. if(!m_localpath.isNull())
  56. fileName = m_localpath + QDir::separator() + fileName;
  57.  
  58. if(QFile::exists(fileName))
  59. {
  60. int i = 0;
  61. QString newfileName = fileName + ".";
  62.  
  63. while(QFile::exists(newfileName + QString::number(i)))
  64. ++i;
  65.  
  66. newfileName += QString::number(i);
  67. QFile fm(fileName);
  68. fm.rename(newfileName);
  69. }
  70.  
  71. QFile file(fileName);
  72. if(file.open(QFile::WriteOnly))
  73. file.write(data);
  74.  
  75. reply->deleteLater();
  76. m_reply->deleteLater();
  77. }
  78.  
  79. void DownloadCommand::downloadCompleted(qint64 d, qint64 size)
  80. {
  81. if((d == 0 && size == 0) || (m_reply->error() != QNetworkReply::NoError))
  82. emit processFinished(tr("Cant download file error is %1").arg(m_reply->errorString()));
  83. else
  84. {
  85. if(size != -1)
  86. emit processChanges(100 * d / size);
  87. else emit processChanges(-1);
  88. if(size == d)
  89. emit processFinished(tr("Download is complete"));
  90. }
  91. }
To copy to clipboard, switch view to plain text mode 
(i copy this code for dont say me give us some code man ) .)

so i think move it to MyThread and then run myThread.exec() every time that i need to download file. ( i ask this question for correct running signals and slots in thread)

thanks.