Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Multithreading ans updating widgets
Multithreading ans updating widgets [message #14726] Tue, 11 March 2008 11:48 Go to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member

Hello,

I have some problems with GUI en multithreading with U++.
My app crash when a thread modify the content of a lineEdit widget.

I think an other thread is trying to read data from this lienEdit to display it at the same time.

How can i disable updating events when i modify my widgets values ?

Thank you for your help

A simple example that produce the problem.


#include "mt.h"

void mt::theThread()
{
	while(true) {
		String text = console.Get();
		text << "Some Text\n";
		console.Set(text);
	}
}


void mt::startButtonEvent()
{
	Thread().Run(THISBACK(theThread));
}

mt::mt()
{
	CtrlLayout(*this, "Window title");
	
	startButton << THISBACK(startButtonEvent);
}

GUI_APP_MAIN
{
	mt().Run();
}


Re: Multithreading ans updating widgets [message #14727 is a reply to message #14726] Tue, 11 March 2008 12:34 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
cocob wrote on Tue, 11 March 2008 06:48


Hello,

I have some problems with GUI en multithreading with U++.
My app crash when a thread modify the content of a lineEdit widget.

I think an other thread is trying to read data from this lienEdit to display it at the same time.

How can i disable updating events when i modify my widgets values ?

Thank you for your help

A simple example that produce the problem.


#include "mt.h"

void mt::theThread()
{
	while(true) {
		String text = console.Get();
		text << "Some Text\n";
		console.Set(text);
	}
}


void mt::startButtonEvent()
{
	Thread().Run(THISBACK(theThread));
}

mt::mt()
{
	CtrlLayout(*this, "Window title");
	
	startButton << THISBACK(startButtonEvent);
}

GUI_APP_MAIN
{
	mt().Run();
}





Only main thread can do GUI. You should use event queue and post callback that is supposed to update the widget.

Reading the widget content in a non-main thread is a bit of problem, I guess you should use shared variable that gets updated on Post event request (and is interlocked by Mutex).

Mirek
Previous Topic: How to modify Page setup (left margin) in RichText Control
Next Topic: Controls & classes design questions
Goto Forum:
  


Current Time: Fri Mar 29 13:00:32 CET 2024

Total time taken to generate the page: 0.01323 seconds