Results 1 to 5 of 5

Thread: QNetworkAccessManager::head not working

  1. #1
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QNetworkAccessManager::head not working

    I have some code like this:

    Qt Code:
    1. QNetworkAccessManager nam;
    2. QNetworkRequest request(url);
    3. m_reply = nam.head(request);
    4.  
    5. connect(m_reply, SIGNAL(readyRead()), this, SLOT(gotNetworkHeader()));
    6. connect(m_reply, SIGNAL(finished(QNetworkReply*)), this, SLOT(headFinished(QNetworkReply*)));
    To copy to clipboard, switch view to plain text mode 

    readyRead and finished are never signaled.
    Does anyone know why?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager::head not working

    Sure. Your object goes out of scope and is destroyed.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QNetworkAccessManager::head not working

    Quote Originally Posted by wysota View Post
    Sure. Your object goes out of scope and is destroyed.
    m_reply is already class scope, but the QNetworkAccessManager object was not.
    I just moved it to class scope, but It still does not work.

    In the constuctor:
    Qt Code:
    1. {
    2. ...
    3. m_nam = new QNetworkAccessManager(this);
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    In a class method:


    Qt Code:
    1. {
    2. m_reply = m_nam->head(QNetworkRequest(url));
    3. connect(m_reply, SIGNAL(readyRead()), this, SLOT(gotNetworkHeader()));
    4. }
    To copy to clipboard, switch view to plain text mode 

    There are are no runtime errors reported by when the connect function is called.

    ...But still no signal is emitted???

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager::head not working

    Do you remember to run the event loop? Does the same request using get instead of head finishes correctly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    jonks (21st October 2009)

  6. #5
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QNetworkAccessManager::head not working

    I got it

    readReady() is the wrong signal.
    I should have been connecting the finished() signal.

    I now works.
    Of course wysota - putting QNetworkAccessManager at class scope is required too.
    Thanks

Similar Threads

  1. Qt+QWebKit+Java+Flash not working
    By progDes in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2009, 17:49
  2. QResource Stopped Working
    By JPNaude in forum Qt Programming
    Replies: 0
    Last Post: 22nd October 2008, 13:26
  3. QDevelop and CTags -> Not working
    By philwinder in forum Qt-based Software
    Replies: 13
    Last Post: 9th May 2008, 22:40
  4. Don't want QTextBrowser to look in working directory
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2007, 00:14
  5. GUI thread and Working thread comunication
    By FasTTo in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 16:31

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.