Qt GUIアプリケーションは、何らかの重要なリアルタイム作業をしていますが、何らかの理由で中断してはいけません。現時点では、GUIとのやりとりがなくても、ボタンをクリックするかフォームをドラッグするとアプリケーションが完璧に実行されていますが、クリックが処理されている間は転送が停止しているようです。フォワーディングはQTimerループで実行されますが、これはGUIスレッドとは別のスレッドに入れていますが、結果に変更はありません。 は、ここでは、コードの一部です:私が先に言ったように、このコードは、任意のデータを損失することなく、アイドルの状況下で細かい実行されているQt GUIアプリケーションはGUIとのやりとり時にリアルタイムプロセスを停止します
class MainWindow : public QMainWindow
{
QSerialPort serialReceiver; // This is the serial object
QTcpSocket *clientConnection;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// Some Initializations ...
QThread* timerthread = new QThread(this); // This is the thread that is supposed to do the forwarding
QTimer *timer = new QTimer(0);
timer->setInterval(25);
timer->moveToThread(timerthread);
connect(timer ,SIGNAL(timeout()),this,SLOT(readserialData())); // Run readserialData() each 25ms
timer->connect(timerthread, SIGNAL(started()), SLOT(start()));
timerthread->start();
}
void MainWindow::readserialData()
{
if(serialReceiver.isOpen())
{
qint64 available = serialReceiver.bytesAvailable();
if(available > 0) // Read the serial if any data is available
{
QByteArray serialReceivedData = serialReceiver.readAll(); // This line would not be executed when there is an interaction with the GUI
if(isClientConnet)
{
int writedataNum = clientConnection->write(serialReceivedData);
}
}
}
}
。私は何か間違っているのですか?
多分http://stackoverflow.com/questions/19252608/using-qthread-and-movetothread-properly-with-qtimer-and-qtcpsocketがお手伝いします – transistor