Results 1 to 4 of 4

Thread: QNetworkReply and "unknown error" problem

  1. #1
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QNetworkReply and "unknown error" problem

    Hi,

    I have seen this question raised on these forums and I feel I have done everything correctly so I was wondering if someone could help point out my fault.

    So I have the following code that behaves as expected when there is a connection to the outside world, however when an error occurs errorString tells me there was an "unknown error". Why?

    Qt Code:
    1. void myClass::checkInternetConnection()
    2. {
    3. qDebug() << "checking internet connection";
    4. QNetworkAccessManager* am = new QNetworkAccessManager;
    5. connect(am, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
    6.  
    7. am->get(QNetworkRequest(QUrl("http://google.com")));
    8. }
    To copy to clipboard, switch view to plain text mode 

    the slot, I would expect this to always be a QNetwokReply::NoError condition.

    Qt Code:
    1. void onFinished(QNetworkReply* r)
    2. {
    3. qDebug() << "Finished checking internet connection" << r->errorString();
    4. emit connectionVaild();
    5. }
    To copy to clipboard, switch view to plain text mode 

    All the best

  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: QNetworkReply and "unknown error" problem

    I am not sure what you want to know.

    Is the problem that the error message is not more descriptive or that finished() is emitted when an error occurs?

    Cheers,
    _

  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QNetworkReply and "unknown error" problem

    If I understand Your question correctly, then r->errorString() has default string if errorString for the internal QIODevice is empty.
    That's because r->error() in this case has QNetworkReply::NoError, and QNetworkReply don't set QIODevice errorString in that condition, and hence, according to the src, default value is returned as "Unknown error".

    Qt Code:
    1. QString QIODevice::errorString() const
    2. {
    3. Q_D(const QIODevice);
    4. if (d->errorString.isEmpty()) {
    5. #ifdef QT_NO_QOBJECT
    6. return QLatin1String(QT_TRANSLATE_NOOP(QIODevice, "Unknown error"));
    7. #else
    8. return tr("Unknown error");
    9. #endif
    10. }
    11. return d->errorString;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Set breakpoint on return values and see for Yourself what is returned, for me it was "return tr("Unknown error");"
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QNetworkReply and "unknown error" problem

    Your QNetworkAccessManager and QNetworkReply are memory leaks. If you call this often or intend running for a long time then you should address these.

Similar Threads

  1. Replies: 32
    Last Post: 26th August 2012, 00:10
  2. protocol "" is unknown QNetworkReply
    By mahadevans87 in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2011, 13:55
  3. "unknown test function error" with MAc
    By tommy in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd August 2008, 19:25
  4. "Treat wchar_t as Built-in Type" to "yes" link error
    By sungaoyong in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 12:45
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 16:58

Tags for this Thread

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.