我是QT的新手。我需要为某个目的使用线程。我在QT中搜索了很多关于线程的内容,但所有文章和视频都使用相同的示例。他们正在使用对话框,并使用2个按钮打印标签上的一些数据。我想用MainWindow使用线程。我的应用程序包括读取串行数据,然后在标签上显示相关信息。该信息包含一个字符串和一个音频文件。字符串和音频文件需要同时播放。我有一个连接的信号串行读取如下:如何在qt中使用线程
connect(&Serial, SIGNAL(readyRead()), this, SLOT(SerialRead()));
QString MainWindow::SerialRead()
{
word Words; //
QString serialData = Serial.readAll(); //Reading Serial Data
//Now here I want to start the two threads
//Thread 1 to display string
//Thread 2 to play audio
return 0;
}
我怎样才能达到上述任务。任何人都可以请参阅我的一些有用的链接或文章。谢谢
您需要另一个生活在工作线程中的对象(c.f.'moveToThread()')。您不能在'MainWindow'中使用插槽。 –
我建议遵循[这篇优秀的文章]中描述的模式(https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ ) – TheDarkKnight