Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Narutogo
Posts: 2
Registered: ‎06-28-2012
My Device: 9810
Accepted Solution

How can I update UI control in non-UI thread

[ Edited ]

Hi, All

 

I want make a custom image view that support URL source.

I start a thread to request the image data from network, then update the image view with the data, but I get the error:

 

ApplicationPrivate::resourceManager: ERROR called from non-UI thread QThread(0x81eeb8c)
ApplicationPrivate::resourceManager: Method called from non-UI thread

 

This is my code segment:

class URLImageView: public CustomControl, public QThread
{
public:
	URLImageView();
private:
	void run();

	ImageView* mImageView;
	Container* mRootContainer;
};

URLImageView::URLImageView()
{
	mRootContainer = Container::create().background(Color::Gray).preferredSize(100,100);
	mImageView = ImageView::create().image(QUrl("asset:///button.png"));

	mRootContainer->add(mImageView);
	setRoot(mRootContainer);
	start();
}

void URLImageView::run()
{
	//get data from network
	//...
	//...
	
//create image from binary data
Image* image = new Image(pixelBuffer); mImageView->setImage(image); }

 

I know in old BB OS (Java Platform), I can get the UI event lock from Application like this:

synchronized (Application.getEventLock())
{
        // I can update UI control here
}

 

Is there same way in BB10 Cascades, or what's the right way if I want update UI in non-ui thread ?

 

Thanks

 

 

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: How can I update UI control in non-UI thread

This sounds like what Signals are useful for, when connected with the QueuedConnection option. I don't have a link for you but I'm sure you can look it up with that description.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
New Contributor
Narutogo
Posts: 2
Registered: ‎06-28-2012
My Device: 9810

Re: How can I update UI control in non-UI thread

Thanks Peter, your tips is very useful for me.

 

Resolved by using signal and slot:

Worker Thread in Qt using Signals & Slots

 

:Yes:

Please use plain text.