gpt4 book ai didi

c++ - wxWidgets 计时器不启动?

转载 作者:搜寻专家 更新时间:2023-10-31 00:52:43 24 4
gpt4 key购买 nike

此 wxWidgets 代码(模拟可移植 sleep )不起作用。

MyClass::MyClass(){
m_timer = std::make_shared<wxTimer>(this, ID_TIMER);
}

void MyClass::WaitOneSecond()
{
m_timer->StartOnce(1000);
while (m_timer->GetInterval() < 1000);
}

当使用 Visual Studio 单步执行 WaitOneSecond 调用时,不会出现延迟。为什么?...

最佳答案

wxwTimerWxWidget 的事件循环一起工作。

这意味着它会在延迟到期后通知您,但您必须交还控制权。

如文档中所述:

There are three different ways to use this class:

  • You may derive a new class from wxTimer and override the wxTimer::Notify member to perform the required action.
  • You may redirect the notifications to any wxEvtHandler derived object by using the non-default constructor or wxTimer::SetOwner. Then use the EVT_TIMER macro to connect it to the event handler which will receive wxTimerEvent notifications.
  • You may use a derived class and the EVT_TIMER macro to connect it to an event handler defined in the derived class. If the default constructor is used, the timer object will be its own owner object, since it is derived from wxEvtHandler.

关于c++ - wxWidgets 计时器不启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50972066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com