UI modifications using ApplicationFramework
Hello.
I am new to NoesisGUI, and taking first steps trying to mate NoesisGUI with RxCpp. I modified Rss example - made a window with ListBox, and trying to insert items based on some data. Actual code is below:
As far as I modified existing example code, I use ApplicationFramework, and from time to time I get application crash in this function:
And also output console full of messages like these:
Obviously I do something wrong with threads, like inserting items from another thread, which is not the way it should be done. Could anyone tell me is it possible to implement UI modifications somewhere in the UI thread loop - using ApplicationFramework, or I need to write my own loop from scratch?
I am new to NoesisGUI, and taking first steps trying to mate NoesisGUI with RxCpp. I modified Rss example - made a window with ListBox, and trying to insert items based on some data. Actual code is below:
Code: Select all
const std::string content = /*some content*/;
if (auto list_box = FindName<ListBox>("listBox")) {
auto item = new ListBoxItem();
item->SetContent(content.c_str());
if (auto items = list_box->GetItems()) {
items->Insert(0, item);
}
}
Code: Select all
void Window::Render(double time)
And also output console full of messages like these:
Code: Select all
[NOESIS/E] The calling thread (26264) cannot access this object (RssReader.MainWindow) because a different thread owns it (31924)
[NOESIS/E] The calling thread (26264) cannot access this object (ListBox) because a different thread owns it (31924)
Re: UI modifications using ApplicationFramework
In case anyone with similar question ever stumbles upon this post:
It seems that the easiest way to do this (since ApplicationFramework source code is available) - to inject rxcpp::schedulers::run_loop to the Display implementation (in my case it is Win32Display class). I ended up with the following code:
And inserted it right before calling
UI-manipulating subscriptions should be made using observe_on like this:
It seems that the easiest way to do this (since ApplicationFramework source code is available) - to inject rxcpp::schedulers::run_loop to the Display implementation (in my case it is Win32Display class). I ended up with the following code:
Code: Select all
/* rlp_ is a shared_ptr<rxcpp::schedulers::run_loop>, created on main thread on application start and provided via DisplayLauncher::Run */
if (rlp_ && !rlp_->empty() && rlp_->peek().when < rlp_->now())
rlp_->dispatch();
Code: Select all
mRender(this);
Code: Select all
auto ui_thread = rxcpp::observe_on_run_loop(*rlp_);
observable.observe_on(ui_thread).subscribe(func);
-
-
sfernandez
Site Admin
- Posts: 2056
- Joined:
Re: UI modifications using ApplicationFramework
Hi, as you found a Noesis View and its UI elements can only be modified from the same thread where the view was created.
Thanks for sharing your integration with RxCpp, I'm sure some people may find it useful.
Thanks for sharing your integration with RxCpp, I'm sure some people may find it useful.
Who is online
Users browsing this forum: No registered users and 1 guest