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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Trusted Contributor
AllSystemGo
Posts: 137
Registered: ‎11-23-2010
My Carrier: Rogers
Accepted Solution

Just need some clarification

Ok so I'm starting to use more and more slot/signals and would like to understand some stuff. I'll post some code and I'll ask my question after.

 

	QString queryUri;

    queryUri = "somewebsite";

    QUrl url(queryUri);
    QNetworkRequest req(url);

    QNetworkReply* ipReply = netManager_->get(req);
    connect(ipReply, SIGNAL(finished()), this, SLOT(onReply()));

    return _feedReply;

 If I understand correctly even if I declare my signal/slot my code continues, cause _feedReply is always empty, and _feedReply was getting populated in my slot. So how can I make my code stop and wait for the result of onReply() to continue and return _feedReply. 

 

Maybe I'm doing it all wrong. But I would like to understand.

 

Thank you!

Please use plain text.
Developer
Zmey
Posts: 896
Registered: ‎12-18-2012

Re: Just need some clarification

[ Edited ]

That's correct. Network requests are asynchronous, they do not block.

Qt application relies on events queue. The events are processed in a event processing loop. You shouldn't wait inside of a function, otherwise the event loop will stop and the application will become unresponsive.

If you absolutely need to do this, in Qt there's QApplication::smileytongue:rocessEvents function which can be called periodically while sleeping in function. I don't know if there's a Cascades equivalent, but it's a bad design and is not recommended.

A better approach is declaring your own signal in header file, and emitting this signal from onReply() slot after the reply is processed:
emit mySignal(myData);
Then subscribe to this signal and do further processing there.

Please use plain text.
Developer
zezke
Posts: 816
Registered: ‎12-12-2010
My Carrier: Mobile Vikings

Re: Just need some clarification

You can't and you shouldn't want to. The point is that you launch a network request (for example by pressing a button) and then wait for the result WITHOUT BLOCKING THE UI! If you would be able to wait in the same method the UI thread would be blocked and the user would experience a non-functioning UI.

 

Just process your results in the onReply method, there's no good reason why that wouldn't work.

-------------------------------------------
Your like is much appreciated!
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Developer
simon_hain
Posts: 13,754
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Just need some clarification

Regarding network requests there is something to add though:
While the request itself is async, the processing of the response is not!
If you do heavy processing you should not do that in the response method.

We are using QtConcurrent::run to process the network responses (soap or xml parsing).
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
zezke
Posts: 816
Registered: ‎12-12-2010
My Carrier: Mobile Vikings

Re: Just need some clarification

Excellent point simon, forgot about it.

-------------------------------------------
Your like is much appreciated!
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Trusted Contributor
AllSystemGo
Posts: 137
Registered: ‎11-23-2010
My Carrier: Rogers

Re: Just need some clarification

Thank you all for your answers. I really appreciate. I'll continu reading to get better at this.
Please use plain text.