Results 1 to 9 of 9

Thread: QNetworkAccessManager problem. It send's nothing

  1. #1
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QNetworkAccessManager problem. It send's nothing

    Hello!!! I have a trouble with QNetworkAccessManager.
    I created new Qt project and use Sample code. It works perfect. But when i try to past my code into existing project. "manager->get(request)" send nothing and finished slot's dosn't fire. I use QT4.6 and Visual Studio 2008. May be i forget to include some directive or debugger option? Another not network slot's work's perfect. All network slots(slotError,slotReadyRead) dosn't fire. Checkpoint.php add's visit record to text file. May be QNetworkAccessManager conflict with existing project?

    I will be very happy if someone could help.

    Qt Code:
    1. const QString url= "http://127.0.0.6/checkpoint.php";
    2. QNetworkRequest request;
    3. request.setUrl(QUrl(url));
    4. request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
    5. qDebug("running");
    6.  
    7. manager = new QNetworkAccessManager(this);
    8. QNetworkReply *reply = manager->get(request);
    9.  
    10. QObject::connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
    11. QObject::connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyHasFinished()));
    12. QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(slotError(QNetworkReply::NetworkError)));
    13.  
    14. QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)),this, SLOT(slotSslErrors(QList<QSslError>)));
    15.  
    16. ....
    17. void MyClass::replyHasFinished(){
    18. AfxMessageBox(_T("replyHasFinished WORKS"));
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by stepchik; 1st April 2011 at 10:46.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QNetworkAccessManager problem. It send's nothing

    Try to declare the replyHasFinished slot with QNetworkReply* parameter:
    Qt Code:
    1. MyClass{
    2. ...
    3. public slots:
    4. void replyHasFinished( QNetworkReply* );
    5. ...
    To copy to clipboard, switch view to plain text mode 
    Show the header for MyClass, maybe replyHasFinished is not declared as slot at all ?
    Maybe you forgot the Q_OBJECT macro ?
    Last edited by stampede; 1st April 2011 at 14:54.

  3. #3
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QNetworkAccessManager problem. It send's nothing

    I try to add ( QNetworkReply* ). It did not solved my problem. Request dos't send (the record of checkpoint file is empty) and replyHasFinished(QNetworkReply*) Slot has not been fired.

    Now MyClass is:

    Qt Code:
    1. class MyClass : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. OptiroamLogic(QCommandLinkButton *commandLinkButton,QLCDNumber *lcdnumber,QWidget *parent = 0, Qt::WFlags flags = 0);
    7. QNetworkReply *reply;
    8. QNetworkAccessManager *manager;
    9.  
    10. private:
    11. // QNetworkAccessManager *manager;
    12. QCommandLinkButton *topUp;
    13. QLCDNumber *displayBalance;
    14.  
    15. private:
    16. QString parseXML(QString str);
    17.  
    18. public slots:
    19. void btnRunBrowser_clicked();
    20. void replyHasFinished(QNetworkReply*);
    21. void sendBalanceRequest();
    22. void slotReadyRead();
    23. void slotError(QNetworkReply::NetworkError);
    24. };
    25. }; // namespace Tel
    To copy to clipboard, switch view to plain text mode 

    May be the reason is in preprocessor Difinitions:

    In work project they are : "UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_NO_DEBUG;ND EBUG;QT_CORE_LIB;QT_GUI_LIB;QT_XMLPATTERNS_LIB"

    In "enemy" project was:
    "WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBYQT4_EXPORTS;UNI CODE"

    I try to play with them. Now:
    "WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBYQT4_EXPORTS;UNI CODE;QT_CORE_LIB;QT_GUI_LIB;QT_XMLPATTERNS_LIB"

    As i see there are not something "QT_NETWORK_LIB". But in "work" project it works. The head of class.h file is
    Qt Code:
    1. #ifdef _WINDOWS
    2.  
    3. #ifdef LIBYQT4_EXPORTS
    4. #define YQT4_API __declspec(dllexport)
    5. #else
    6. #ifndef LIBYQT4_STATIC
    7. //#define YQT4_API __declspec(dllimport)
    8. #endif
    9. #endif
    10.  
    11. #endif /* _WINDOWS */
    12.  
    13. #ifndef YQT4_API
    14. #define YQT4_API
    15. #endif
    16.  
    17. #undef open
    18. #undef read
    19. #undef close
    20. #undef write
    21. #undef mkdir
    22. #include <string.h>
    23. #include <stdlib.h>
    24. #include <stdio.h>
    25.  
    26. //#define QT_NO_DEBUG
    27. //#define QT_DLL
    28. //#define QT_GUI_LIB
    29. //#define QT_CORE_LIB
    30. //#define QT_THREAD_SUPPORT
    31.  
    32. #include <QtGui>
    33. #include <QSound>
    34. #include <QNetworkReply>
    To copy to clipboard, switch view to plain text mode 

    And in code i saw something like "one thread supply" - may be this is the reason?

    I gonna try to send request throw InternetOpenUrl() and see "checkpoint" file.

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

    Default Re: QNetworkAccessManager problem. It send's nothing

    Do you have a Qt event loop running?
    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. #5
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QNetworkAccessManager problem. It send's nothing

    I haven't event loop. it looks like I understood my mistake.
    QNetworkReply *reply = manager->get(request);
    When i go to "get" definition "std::num_get<Elem,Init::get(...)>". Wrong path.

  6. #6
    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: QNetworkAccessManager problem. It send's nothing

    If you have no Qt event loop running then QNetworkAccessManager is going to have a hard time processing your queued requests and sending the notification of completion. If you haven't got the connections between signal and slot right, especially the QNetworkReply* argument, then you should receive a warning to that effect in your console when the program runs.

    The stuff regarding std::num_get has nothing to do with this.

  7. #7
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QNetworkAccessManager problem. It send's nothing

    going to have a hard time processing your queued requests and sending the notification of completion
    Hard time? How mach 5 minutes? May be a half of an our? Does it mean that finally it sends request?

    I'll try to move "request send code" to another process. It does't work yet. Can you explain where should i place event loop? Should i place in run() function?

    Something like that?
    Qt Code:
    1. void MyThread::run(){
    2. QEventLoop loop;
    3. AfxMessageBox(_T("My Thread"));
    4. QNetworkAccessManager *_manager = new QNetworkAccessManager();
    5. QNetworkRequest *_request = new
    6. QNetworkRequest(QUrl("http://127.0.0.6/checkpoint.php"));
    7. QNetworkReply *_reply = _manager->QNetworkAccessManager::get(*_request);
    8. QObject::connect(_reply, SIGNAL(readyRead()), this, SLOT(slot_finished()));
    9. QObject::connect(_reply, SIGNAL(finished()), this, SLOT(slot_finished()));
    10. QObject::connect(_reply, SIGNAL(error()), this, SLOT(slot_finished()));
    11. loop.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QNetworkAccessManager problem. It send's nothing

    As i understood the reason is fact that my code compiling as DLL. Before i try to use QEventLoop, Qtime with timeout(0). QEventLoop dosn't work. Qtime timeout_slot works, but QNetworkAccessManager send's nothing.

  9. #9
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QNetworkAccessManager problem. It send's nothing

    Finally the problem has not been solved. I had to use CURL.

Similar Threads

  1. Replies: 6
    Last Post: 7th November 2012, 05:13
  2. QNetworkAccessManager problem instantiating
    By hojoff79 in forum Qt Programming
    Replies: 8
    Last Post: 9th February 2011, 04:59
  3. send mail from qt app problem
    By cutie.monkey in forum Qt Programming
    Replies: 12
    Last Post: 30th September 2010, 19:31
  4. qnetworkaccessmanager problem!
    By novamaster in forum Qt Programming
    Replies: 6
    Last Post: 7th August 2010, 11:46
  5. Replies: 0
    Last Post: 30th August 2009, 15:18

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.