如何防止长进程挂起wxwidgets窗口
How to prevent a long process to hangs wxwidgets window
我有一个wxwindows应用程序,在按钮的onclick事件中,我有一段很长的过程,例如,我有这样的东西:
for(int i=1;i<100;i++)
{
sleep(1000);
gaugeProgress->SetValue(i);
*textOutput<<i;
}
运行此代码会停止UI响应。我添加
Refresh();
Update();
之后
*textOutput<<i;
但它没有起作用。
有什么办法可以让我把这些事件说出来吗?
我正在使用VS 20102 在Windows上工作
在这些情况下,我使用wxYield(),如下所示:
for(int i = 1; i < 100; i++)
{
// sleep() freezes the program making it unresponsible.
// sleep(1000);
gaugeProgress->SetValue(i);
*textOutput << i;
// wxYield stops this function execution
// to process all the rest of stocked events
// including the paint event and resumes immediately.
wxYield();
}
这将停止当前进程,并允许应用程序像绘制事件一样处理消息堆栈。
但我认为正确的方法应该是使用线程。
您可以在wxwindows中添加wxTimer成员,在窗口构造函数中启动它,例如:
m_timer.Start(1000);
然后用一个函数捕获计时器事件,例如:
void mywindow::OnTimer(wxTimerEvent& event)
{
Refresh();
Update();
}
请确保将事件连接到wxTimer成员。
相关文章:
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 问:如何使用C++中的按钮从窗口打开窗口
- SDL 窗口不会弹出
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 如何在cpp文件之间切换窗口?在Qt中
- 使用标准窗口与wxWidgets一起绘制?
- Wxwidgets - 如何添加调整大小事件处理程序以使"X"绘图随窗口调整大小?
- wxWidgets - 阻止 OS X 上的窗口模式对话框
- 2个线程 - 一个带有OpenGL窗口的线程,第二个带有WXWIDGETS的窗口
- 如何处理 WXWIDGETS 中父窗口的鼠标事件
- wxwidgets 自定义事件不会传播到父窗口
- 如何在wxWidgets的同一窗口中拖放文件和文本
- wxwidgets UI 更新:声明窗口标识符
- 带有 wxWidgets 的独立文件对话框窗口
- wxwidgets 错误窗口.H 已包括在内
- 有没有办法在wxWidgets 2.8+中保存窗口大小信息
- 如何防止长进程挂起wxwidgets窗口
- 如何在wxWidgets中将键盘焦点设置为NULL窗口
- 创建一个简单的窗口来输出用于调试的信息(日志样式)- wxWidgets
- wxWidgets(甚至OOP GUI)多个窗口