What I'm trying to achieve is simply a game loop. I could use a QTimer set to the desired frame rate. But I chosed to try existing approach I already use with Win32 API. I will post my code here so it can be tested:

Qt Code:
  1. tbb::tick_count t0, t1;
  2.  
  3. MyGame2::MyGame2(QWidget *parent, Qt::WFlags flags)
  4. : QMainWindow(parent, flags)
  5. {
  6. ui.setupUi(this);
  7.  
  8. ui.textEditMainConsole->appendPlainText("Hello!");
  9. //ui.textEditMainConsole->setDisabled(true);
  10. //ui.textEditMainConsole->clear();
  11.  
  12. //hiResTimerStart = boost::chrono::steady_clock::now();
  13. t0 = tbb::tick_count::now();
  14.  
  15. timer.setInterval(0);
  16. timer.start();
  17.  
  18. connect(&timer, SIGNAL(timeout()), this, SLOT(OnIdle()));
  19. }
  20.  
  21. MyGame2::~MyGame2()
  22. {
  23. timer.stop();
  24. }
  25.  
  26. extern QApplication *pApp;
  27.  
  28. void MyGame2::OnIdle()
  29. {
  30. tbb::tick_count t1 = tbb::tick_count::now();
  31. float dt = (t1 - t0).seconds();
  32. //boost::chrono::steady_clock::time_point hiResTimerEnd = boost::chrono::steady_clock::now();
  33. //boost::chrono::microseconds msecs = boost::chrono::duration_cast<boost::chrono::microseconds>(hiResTimerEnd - hiResTimerStart);
  34.  
  35. //unsigned long p = 1000000/60;
  36. //unsigned long p = 1000000/85;
  37. //if (msecs.count() < p) {
  38. if (dt < 1.0f/60) {
  39.  
  40. } else {
  41. //============
  42.  
  43. std::stringstream ss;
  44. //ss << "~~~ dCount: " << msecs.count();
  45. ss << "~~~ dCount: " << dt;
  46. std::string s = ss.str();
  47.  
  48. //ui.textEditMainConsole->clear();
  49. //ui.textEditMainConsole->appendPlainText(s.c_str());
  50. ui.textEditMainConsole->setPlainText(s.c_str());
  51. //============
  52.  
  53. //hiResTimerStart = hiResTimerEnd;
  54. t0 = t1;
  55. }
  56.  
  57. pApp->processEvents();
  58. }
To copy to clipboard, switch view to plain text mode