QTimer::singleShot and QMetaMethod::invoke

后端 未结 3 1661
醉梦人生
醉梦人生 2021-01-01 19:26

In some Qt examples, I see they use QTimer::singleShot(0, this , SLOT(funcA())), why not to call the slot funcA directly? also the same question f

3条回答
  •  爱一瞬间的悲伤
    2021-01-01 19:50

    Every system has a event loop where events are processed. Say like

    application::processEvents()
    {
    // process event list..
    }
    

    Now the place where you write QTimer::singleShot(0, this, SLOT(doSomething())); might be inside some processing event. When this loop is done, processEvents will be called again and in that the doSomething() will be executed.

    So this is like calling doSomething in the next event loop, rather than calling it immediately. Hope you get the idea.

提交回复
热议问题