QThreads , QObject and sleep function

前端 未结 4 1095
醉梦人生
醉梦人生 2020-12-16 04:18

The problem I encountered is that I decided to implement QThreads the way they are supposed to, based on numerous articles:
http://blog.qt.digia.com/blog/20

4条回答
  •  隐瞒了意图╮
    2020-12-16 04:41

    I agree with jalf. I have a thread that acts as a sort of DBUS daemon and needs to listen to messages forever. Two things to mention:

    jalf has

    void sleep(int ms) { QThread::sleep(ms); }
    

    But this is NOT MILLISECONDS! QThread::sleep() takes seconds. Also, if one is to take this approach, he must also include the QThread lib anyway, so it might be easier to just make the call like this:

    QThread::sleep(seconds);
    

    directly in the code. That way there isn't an extra header file. I ran this and it also works as jalf explained. (putting the calling thread to sleep.)

提交回复
热议问题