Results 1 to 4 of 4

Thread: slots/signals with QNetworkReply

  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Default slots/signals with QNetworkReply

    I cannot figure out how to properly use slots/signals when QNetworkReply detects an error.
    I'm trying to detect a website that doesn't exist and I'd like to see "host not found" error.
    This is the main code:

    Qt Code:
    1. QNetworkAccessManager* nam; QNetworkReply* reply;
    2. nam = new QNetworkAccessManager(this);
    3. QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
    4.  
    5. QUrl url; url.setUrl("http://www.random-wrong-website.com");
    6. reply = nam->get(QNetworkRequest(url));
    To copy to clipboard, switch view to plain text mode 

    Here's my slot slotError()
    Qt Code:
    1. void MyClass::slotError(QNetworkReply* reply)
    2. {
    3. //extract the error code from here
    4. }
    To copy to clipboard, switch view to plain text mode 

    My questions:
    1) Am I calling the slot correctly? I have a feeling I don't have the parameters right.
    2) Do you know how to find out (in slotError()) what the error code was

    Please help if you can. Thanks!!

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: slots/signals with QNetworkReply

    Replace this line in slot definition.
    Quote Originally Posted by timmu View Post
    void MyClass::slotError(QNetworkReply* reply)
    With
    Qt Code:
    1. void MyClass::slotError(QNetworkReply::NetworkError err)
    To copy to clipboard, switch view to plain text mode 

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

    timmu (24th August 2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: slots/signals with QNetworkReply

    thanks!

    But what would be the slotError() prototype declaration in the h file? These don't work:

    Qt Code:
    1. void slotError(class QNetworkReply);
    2. or
    3. void slotError(QNetworkReply::NetworkError err);
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: slots/signals with QNetworkReply

    The slot signature should match the signal you want to connect it to ...

Similar Threads

  1. QNetworkReply error handling
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 25th August 2009, 09:07
  2. Finding filename from QNetworkReply
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2009, 09:29
  3. Custom QNetworkReply for WebView
    By victor.yacovlev in forum Qt Programming
    Replies: 0
    Last Post: 1st April 2009, 13:32
  4. When to delete QNetworkReply?
    By QPlace in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2009, 12:46
  5. Inheritance and Slots/Signals
    By LMZ in forum Qt Programming
    Replies: 5
    Last Post: 4th June 2007, 19:43

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.