Results 1 to 6 of 6

Thread: QNetworkAccessManager not receiving data in Android, but works in Desktop

  1. #1
    Join Date
    Jul 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QNetworkAccessManager not receiving data in Android, but works in Desktop

    I have a very simple GET request, which works fine in Desktop Qt, but no data is returned when I run it on Android:

    Qt Code:
    1. QNetworkManager m_WebCtrl;
    2. QNetworkReply reply;
    3. QUrl url("http://www.google.com");
    4. request.setUrl(url);
    5. reply = m_WebCtrl.get(request);
    6.  
    7. // Infinite loop to watch the data come in
    8. while (1) {
    9. qDebug()<< "Data! " << reply->bytesAvailable();
    10. }
    To copy to clipboard, switch view to plain text mode 

    The Android device has an IP address that is in the valid range. I don't see any errors with reply->error(). What can this be related to?

    Edit: I should add that I'm using Qt 5.4 beta.
    Last edited by kubark42; 7th November 2014 at 06:01.

  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 receiving data in Android, but works in Desktop

    That should not work on the desktop either, your while loop is blocking the event loop.

    You don't need the while loop, just connect to the network reply's readyRead() signal.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager not receiving data in Android, but works in Desktop

    Quote Originally Posted by anda_skoa View Post
    That should not work on the desktop either, your while loop is blocking the event loop.

    You don't need the while loop, just connect to the network reply's readyRead() signal.

    Thanks for the comment. I'm guessing the stripped down version I showed above works because of the time it takes to print the qDebug() statement. But I updated the original code sample with a QEventLoop for clarity.

    The full code uses the readyRead() signal, but I observe identical behavior. The readyRead() signal is never called.

    =====================
    New code with QEventLoop:

    Qt Code:
    1. QNetworkManager m_WebCtrl;
    2. QNetworkReply reply;
    3. QUrl url("http://www.google.com");
    4. request.setUrl(url);
    5. reply = m_WebCtrl.get(request);
    6.  
    7. // Infinite loop to watch the data come in
    8. while (1) {
    9. QEventLoop eventloop;
    10. QTimer::singleShot(1000, &eventloop, SLOT(quit()));
    11. eventloop.exec();
    12.  
    13. qDebug()<< "Data! " << reply->bytesAvailable();
    14. }
    To copy to clipboard, switch view to plain text mode 

  4. #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 receiving data in Android, but works in Desktop

    Why do you have a timer instead of connecting to the signal you are waiting for (readyRead)?
    Or even connect to the finished() signal if you want to proceed once the full response has been received?

    Cheers,
    _

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

    fecub (20th November 2014)

  6. #5
    Join Date
    Jul 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager not receiving data in Android, but works in Desktop

    Quote Originally Posted by anda_skoa View Post
    Why do you have a timer instead of connecting to the signal you are waiting for (readyRead)?
    Or even connect to the finished() signal if you want to proceed once the full response has been received?
    _
    I guess I could have been clearer in my prior two posts when I said that the full code properly uses sockets.

    I've tracked the problem down to the individual piece of hardware. The true URL I've been trying to access is http://192.168.122.1:8080/liveview/liveviewstream, but of course I don't figure anyone here has a Sony Camera handy. What's puzzling me is that the Android device can access the camera just fine, it's only Qt that has a problem.

    This is getting harder to debug, since it certainly looks like a bug (works with Sony Camera API on Qt Desktop, works with Android Chrome, works with Sony's java app), but I'm unsure how to post a minimal code set that can be tested.

    What I have noticed as well is that sometimes non-standard ports cause the QNetworkReply to fail. It's intermittent on Qt Android, but never fails on Qt Desktop. For instance, replacing http://google.com with http://open.zorinaq.com:1337/ in the above code leads to frequent failures. Might be related.

  7. #6
    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 receiving data in Android, but works in Desktop

    Quote Originally Posted by kubark42 View Post
    What I have noticed as well is that sometimes non-standard ports cause the QNetworkReply to fail. It's intermittent on Qt Android, but never fails on Qt Desktop. For instance, replacing http://google.com with http://open.zorinaq.com:1337/ in the above code leads to frequent failures. Might be related.
    Maybe, now that you have a publicly usable URL to test with, you could post code that triggers the problem for you and is not using some obscure while loop hack that your actual program is not using anyway.

    Cheers,
    _

    P.S.: since you encounter your problem on a system with an access restrictions system, have you verified that your program has actually been granted the permissions you need?

Similar Threads

  1. Deploying desktop application on android
    By Baso in forum Installation and Deployment
    Replies: 0
    Last Post: 3rd December 2013, 18:08
  2. Kit Desktop is incompatible with kit Android for x86 (GCC 4.7, Qt 5.1.0).
    By tsuibin in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th July 2013, 09:20
  3. Problem with receiving Data from TcpSocket
    By Basti300 in forum Qt Programming
    Replies: 0
    Last Post: 15th July 2010, 14:41
  4. QTcpSocket + receiving data
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 08:10
  5. data at fifo's receiving end has arrived?
    By quickNitin in forum General Programming
    Replies: 4
    Last Post: 5th November 2006, 10: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.