c++ - What's the quickest way to return the contents of a webpage in Qt? -


So, I'm trying to run some simple code in QT to return the contents of a given web page I am After a quick research, I was able to develop my own class to simplify the process:

  WebFetch :: WebFetch () = New QNetworkAccessManager (this); Connect (name, signal (end (QN network code *)), this, slot (Finish (QN NetworkCar * *)); } QString WebFetch :: get (QString url) {nam- & gt; Get (QNetworkRequest (QUrl (url))); } Zero WebFetch :: Finish (QNetworkReply * Answer) {QByteArray Data = Answer-> readAll (); Cue string straw (data); }   

However, I have a big problem with the code above that the call is asynchronous; I will prefer the "get" function to return the string only after receiving it, But it seems impossible that he has to wait for the finished signal, there is no way to "get" at that point which retrieves anything that has an option for the above method by the "finished" slot. Or am Is there any way that I can receive "to bring back the content of" "end"? Any help would be greatly appreciated. Thanks!

Asynchronous calls are not a problem - this is a big win, with a synchronous call Essentially the potential hundreds are wasting the OK KK's RAM, and a whole thread, just waiting to come back from laziness. You can not do this while writing this kind of code that will not comment on the insanity of running this kind of synchronous code in the GUI thread, either synchronously, or even "quick" while saying these things. This is also a very bad idea to run a local event loop because suddenly all of your GUI codes are reentrant. My condition is that you do not have to design or test for it.

Whatever code you expect in two parts, it needs to be broken: The first part needs to be requested, the second part is notified in a slot, when the request ends and what it does He has to continue to do it.

If you want to do it all in one method, then C ++ 11:

  QNetworkAccessManager * mgr = ...; QObject :: Connect (MGR, & QNetworkAccessManager :: End, [this, MGR] (QNetworkReply * Answer) {// Here you can talk with answers}); MGR- & gt; Receive (kinetarkeuistest ("....");   

For a complete example, which draws random images from Imgur, it is largely used in asynchronous, multi-threaded processing and lambda. Does style up.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -