Results 1 to 4 of 4

Thread: QNetworkAccessManager, not using it right?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QNetworkAccessManager, not using it right?

    Hi!

    I want to write a program that issues get, put, and delete HTTP requests. I tried to use the QNetworkAccessManager to accomplish this, but somehow not even a simple example works for me. Here is my code:

    Qt Code:
    1. QNetworkAccessManager nm;
    2. QNetworkReply* nr = nm.get(QNetworkRequest(QUrl(QString("http://www.yahoo.com"))));
    3. while (!nr->isFinished())
    4. {
    5. sleep(10);
    6. qDebug() << nr->isFinished() << nr->error() << (nr->request()).url();
    7. }
    To copy to clipboard, switch view to plain text mode 

    And the output is:

    qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method
    qt.network.ssl: QSslSocket: cannot resolve SSLv2_server_method
    false 0 QUrl( "http://www.yahoo.com" )
    false 0 QUrl( "http://www.yahoo.com" )
    false 0 QUrl( "http://www.yahoo.com" )
    false 0 QUrl( "http://www.yahoo.com" )
    false 0 QUrl( "http://www.yahoo.com" )
    false 0 QUrl( "http://www.yahoo.com" )
    false 0 QUrl( "http://www.yahoo.com" )
    First of all, what are the SSL socket warnings about? I did not want to use an SSL connection here.
    I used wireshark to observe the network traffic, and can see that not a single packet leaves my interface when using this code. It is not working.

    And yes, I do not want to use the QNetworkManager in an asynchronous mode, I would rather wait in a loop until it is finished.

    Can anyone tell me what I'm doing wrong?

    Thanks
    Cruz

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager, not using it right?

    When you "sleep()" you are blocking the thread, it can't do any of the operations you are asking it to perform.

    You need to allow the Qt event loop to process events.

    One option is to use a nested event loop

    Qt Code:
    1. connect(nr, SIGNAL(finished()), &loop, SLOT(quit())); // or the equivalent function pointer based syntax
    2. loop.exec();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to anda_skoa for this useful post:

    Cruz (24th November 2016)

  4. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager, not using it right?

    Okay this works. What are the SSL warnings about? How do I get rid of them?

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager, not using it right?

    Not sure, maybe a missing OpenSSL library?

    But since you don't need SSL, you can just ignore those.

    Cheers,
    _

Similar Threads

  1. How to use QNetworkAccessManager
    By lni in forum Qt Programming
    Replies: 5
    Last Post: 15th June 2016, 20:12
  2. Example for QNetworkAccessManager with SSL
    By KeineAhnung in forum Newbie
    Replies: 1
    Last Post: 12th February 2016, 13:52
  3. How to use QNetworkAccessManager?
    By radmir in forum Newbie
    Replies: 1
    Last Post: 25th February 2013, 14:43
  4. QNetworkAccessManager
    By cuteatul in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2011, 05:34
  5. QNetworkAccessManager and redirections
    By alexandernst in forum Qt Programming
    Replies: 33
    Last Post: 22nd September 2010, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.