Strange behavior of property in callback #607
-
Hi all, I've compiled and ran cpp-template. appwindow.60
main.cpp
I expect Moreover, close button is not responding when do_job is running, but I think this is expectable. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
You are not supposed to block the UI thread or the eventloop will not run. So you must do the processing operation in a different thread, and use sixtyfps::invoke_from_event_loop from the other thread to communicate back to the UI thread. int main(int argc, char **argv)
{
auto ui = AppWindow::create();
auto do_job = [&ui]{
sixtyfps::invoke_from_event_loop([&ui] {
ui->set_progress(0.f);
});
for(int i = 1; i <= 100; ++i)
{
std::cout << "at i = " << i << std::endl;
// some data processing here (file reading, etc.)
std::this_thread::sleep_for(std::chrono::milliseconds{100});
sixtyfps::invoke_from_event_loop([&ui, i] {
ui->set_progress(float(i));
});
}
};
ui->on_request_increase_value([&]{
std::thread(do_job);
ui->set_counter(ui->get_counter() + 1);
ui->set_progress(-1.);
});
ui->run();
return 0;
}
I hope this helps |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
You are not supposed to block the UI thread or the eventloop will not run. So you must do the processing operation in a different thread, and use sixtyfps::invoke_from_event_loop from the other thread to communicate back to the UI thread.
Example: (I did not test it so you might need to do some fixes)