编辑:下面的解决方案
使用 Wt(版本 3)C++ 框架: 单击调用函数的 WPushButton 时:
button->clicked(boost::bind(&Service::burn, this));
如何以这种方式卡住屏幕(或所有按钮),以至于在函数运行时(运行相当长的时间)无法点击任何东西。目前,当函数 Service::burn() 运行时,我可以单击在函数 Service::burn() 完成后排队并执行的其他按钮。
请注意,卡住后需要恢复所有按钮/屏幕。还有一个功能:
解决方法:
Wt::WPushButton* spec_button;
void testclass::test_only()
{
spec_button = new Wt::WPushButton("slow func");
auto some_long_func = [&](){
cout << "#######start \n";
std::this_thread::sleep_for(std::chrono::seconds(1));
cout << "#######end \n";
spec_button->setDisabled(false);
};
content()->addWidget(spec_button);
spec_button->clicked().connect(spec_button, &WPushButton::disable);
spec_button->clicked().connect(boost::bind<void>(some_long_func));
}
最佳答案
这应该有效:
button->clicked(button, &WPushButton::disable);
button->clicked(boost::bind(&Service::burn, this));
因此,您使用第一个处理程序禁用 UI,然后使用第二个处理程序启动繁重的长进程。
如果您将这两个处理程序放在一个调用中,它将不起作用,因为在该调用完成之前,UI 更改不会传播到浏览器。
关于c++ - 单击按钮后,Wt C++ 使窗口不可单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47223887/