Qt interface class

Qt interface class

本文关键字:class interface Qt      更新时间:2023-10-16

我想使用这样一个main:

int main()
{
   if (param)
      QtDisp *disp = new QtDisp(); //no visual result
   else
      SDLDisp *disp = new SDLDisp();
   disp->init(param); //displays the window
 
   while (1)
   {
      disp->change_color(colour); //change background colour
      sleep(1);
   }
}

它与SDLDisp一起工作,现在我必须创建QtDisp。

我不知道如何处理阻塞的exec()。首先,我想使用Qthread,但显示必须在第一个线程中。

Qt是基于事件的驱动框架。没有事件循环,所有gui部分都无法工作。除了另一个线程中的暴力计算之外,几乎所有的事情都需要在事件循环中完成。Exec()方法启动该事件系统。因此,在调用exec()之前,您将无法做一些有用的事情。最简单的方法是这样做:

int delay = 10; //msec
QTimer *colorChangeTimer() = new QTimer();
colorChangeTimer->setSingleshot(false);
connect(colorChageTimer, SIGNAL(timeout()), disp, SLOT(onTimerChageColor()));
colorChageTimer->start(delay);
int result = QApplication::exec();
delete colorChangeTimer;
return result;