Results 1 to 6 of 6

Thread: QNetworkAccessManager does not signal finished

  1. #1
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QNetworkAccessManager does not signal finished

    Hello all,
    I begin to play with Qt and got stuck with QNetworkAccessManager.
    I can not find any difference to the provided example (googlesuggest), but the example works and my code does not

    It seems that the network manager doesn't emit finished signal.

    The project consists of two classes, one is GUI, second should should access web.

    debugging output is:
    Qt Code:
    1. Starting D:\documents\programming\slovnik-prekladac-qt\Dict-build-desktop\debug\Dict.exe...
    2. translateText called
    3. translateText ends
    4. D:\documents\programming\slovnik-prekladac-qt\Dict-build-desktop\debug\Dict.exe exited with code 0
    To copy to clipboard, switch view to plain text mode 

    header:
    Qt Code:
    1. #ifndef TRANSLATE_H
    2. #define TRANSLATE_H
    3. #include <QString>
    4. #include <QtNetwork>
    5. class Translate :public QObject
    6. {
    7. Q_OBJECT
    8. public:
    9. Translate();
    10. void translateText(QString which);
    11. public slots:
    12. void dataRcd(QNetworkReply *nt);
    13. signals:
    14. void textTranslated(QString *result);
    15.  
    16. private:
    17. QNetworkAccessManager netmanager;
    18. };
    19. #endif // TRANSLATE_H
    To copy to clipboard, switch view to plain text mode 
    code:
    Qt Code:
    1. #include "translate.h"
    2. #include <QtDebug>
    3. Translate::Translate()
    4. {
    5. QObject::connect(&netmanager,SIGNAL(finished(QNetworkReply*)),this,SLOT(dataRcd(QNetworkReply*)));
    6. }
    7.  
    8. void Translate::dataRcd(QNetworkReply *nt){
    9. qDebug()<<"dataRcd called";
    10. emit textTranslated(new QString ("slot dataRcd called"));
    11. }
    12.  
    13. void Translate::translateText(QString which){
    14. qDebug() <<"translateText called";
    15. emit textTranslated(new QString("pre network manager"));
    16. QNetworkRequest req(QUrl("http://www.google.com"));
    17. netmanager.get(req);
    18. qDebug()<<"translateText ends";
    19. }
    To copy to clipboard, switch view to plain text mode 

    Any advice or hint would be a great help.

    Cheers
    lukas
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QNetworkAccessManager does not signal finished

    See the network reply error for possible errors.
    Last edited by tbscope; 17th November 2010 at 05:43.

  3. #3
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QNetworkAccessManager does not signal finished

    not sure if I am doing it right...
    I changed it to
    Qt Code:
    1. void Translate::translateText(QString which){
    2. qDebug() <<"translateText called";
    3. emit textTranslated(new QString("pre network manager"));
    4. QNetworkRequest req(QUrl("http://www.google.com"));
    5. QNetworkReply *rpl = netmanager.get(req);
    6. qDebug()<<rpl->errorString();
    7. qDebug()<<rpl->error();
    8. qDebug()<<"translateText ends";
    9. }
    To copy to clipboard, switch view to plain text mode 
    output is now
    Qt Code:
    1. translateText called
    2. "Unknown error"
    3. 0
    4. translateText ends
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: QNetworkAccessManager does not signal finished

    Hello. Apologies for posting on such an old thread, I'm new to the forum.

    I've got the same exact problem, and I just can't figure out the solution. Has anyone got tips? Should I post my project here?

    Thank you

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,688
    Thanks
    13
    Thanked 1,598 Times in 1,526 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QNetworkAccessManager does not signal finished

    The example in the zip file does not compile as-is. However, the problem appears to be that the Translate object is stack allocated and goes out of scope and is destroyed before a reply can be received.

    If you still cannot see the problem then post a compilable example that shows what you think is broken.

  6. The following 2 users say thank you to ChrisW67 for this useful post:

    lukas.zachy (10th June 2011), merajc (26th January 2011)

  7. #6
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: QNetworkAccessManager does not signal finished

    Thanks for the reply, that was exactly the problem.

    I made the object heap-allocated and it did not work. I then simply added a destructor and it worked.

Similar Threads

  1. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 19:27
  2. Replies: 0
    Last Post: 24th May 2010, 09:11
  3. get finished signal from a thread
    By ProTonS in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2009, 15:17
  4. QProcess object not emitting finished(int) signal
    By Tiansen in forum Qt Programming
    Replies: 13
    Last Post: 14th November 2008, 13:17
  5. QUrlOperator doesn't emit finished signal
    By hayati in forum Qt Programming
    Replies: 16
    Last Post: 26th March 2007, 21:25

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.