「Qtの基礎 - マルチスレッド」の版間の差分

ナビゲーションに移動 検索に移動
607行目: 607行目:
  void MainWindow::onBtnClicked()
  void MainWindow::onBtnClicked()
  {
  {
    //-> マルチスレッド開始
     QEventLoop eventLoop;
     QEventLoop eventLoop;
     QtConcurrent::run([this, &eventLoop]()
     QtConcurrent::run([this, &eventLoop]()
     {
     {
       Delay(5000);
       heavyFunction(); // 時間の掛かる処理
       eventLoop.quit();
       eventLoop.quit();
     });
     });
     eventLoop.exec();
     eventLoop.exec();
    //<- マルチスレッド終了
   
   
     return;
     return;
}
void MainWindow::Delay(int ms)
{
    QEventLoop loop;
    QTimer::singleShot(ms, &loop, &QEventLoop::quit);
    loop.exec();
  }
  }
  </syntaxhighlight>
  </syntaxhighlight>

案内メニュー