窗口文件cmainwindow.cpp
CMainWindow
::CMainWindow(QWidget*parent):
QMainWindow(parent),
ui(newUi::CMainWindow)
{
ui->setupUi(this);
....
connect(threadA,SIGNAL(signalUpdateData(QString)),this,SLOT(slotUpdateDate(QString)),Qt::DirectConnection); // 事件同步传递
...
}

voidCMainWindow::slotUpdateDate(QStringtext)
{
qDebug("receivesignalshowMsg");
ui->label->setText(text);
}


线程文件csubthread.cpp:
voidCSubThread::run()
{
qDebug()<<"run";

while(!isStopped)
{
qDebug()<<this->objectName()<<"run...,"<<QTime::currentTime().toString();

emitsignalUpdateData(QTime::currentTime().toString());
qDebug("has post signal");

QThread::msleep(2000);
}
}

输入出:

"ThreadA" run..., "11:23:45"

receive signal showMsg

has post signal

"ThreadA" run..., "11:23:47"

receive signal showMsg

has post signal




相关文章:

  • 2022-02-07
  • 2020-04-20
  • 2021-08-09
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
猜你喜欢
  • 2022-01-03
  • 2021-05-16
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案