×

Discussion Board

Results 1 to 4 of 4

Threaded View

  1. #1
    Regular Contributor
    Join Date
    May 2009
    Posts
    50

    qt http request problem

    Hello I am using Carbide C++ 2.0.2 with Nokia N97 SDK 1.0. The following code works well with the Emulator. However when I try on device debug configuration the status code in "httpFinished" method returns empty. I can not get the text of requsted url. At the time of on device debug, the Nokia N97 is already connected to the access point at home (my wireless modem) and the browser works fine. I am using self signing configuration (self sign sis file).

    Although my device is connected to the accesspoint (browser is working fine), Do I need to set the access point in the code? If not, what can be the problem with this http request?


    ****************************************************************************************************************
    Here is the header file:

    Code:
    #ifndef QTINTERNET_H
    #define QTINTERNET_H
    
    #include <QtGui/QMainWindow>
    #include "ui_QTInternet.h"
    #include <QMessageBox>
    #include <qtimer.h>
    #include <stdlib.h>
    #include <QtNetwork/qhttp.h>
    #include <QtNetwork/qnetworkaccessmanager.h>
    #include <QtNetwork/qnetworkrequest.h>
    #include <QtNetwork/qnetworkreply.h>
    #include <qurl.h>
    #include <qplaintextedit.h>
    
    class QTInternet : public QMainWindow
    {
        Q_OBJECT
    
    public:
    	QTInternet(QWidget *parent = 0);
        ~QTInternet();
    private slots:
    	void fetch_clicked();
    	void httpFinished(QNetworkReply* reply);
    private:
        Ui::QTInternetClass ui;
        QString urlArray[3];
        QHttp *myHttp;
        QNetworkAccessManager*  netMan;
    };
    
    #endif // QTINTERNET_H
    
    
    *************************************************************************************************
    Here is the cpp file:
    
    
    #include "QTInternet.h"
    
    QTInternet::QTInternet(QWidget *parent)
        : QMainWindow(parent)
    {
    	ui.setupUi(this);
    	connect(ui.fetchbutton,SIGNAL(clicked()), this, SLOT(fetch_clicked()));
    	netMan = new QNetworkAccessManager(this);
    	QObject::connect(netMan, SIGNAL(finished(QNetworkReply*)),this, SLOT(httpFinished(QNetworkReply*)));
    }
    
    QTInternet::~QTInternet()
    {
    
    }
    
    
    void QTInternet::httpFinished(QNetworkReply* reply){
    
    // Reading attributes of the reply
        QVariant statusCodeV = 
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
     
    	//int randomSayi = rand()%3;
    
    	QMessageBox msgBox;
    	//QString number(statusCodeV.toInt());
    	//msgBox.setText(number);
    	//msgBox.setEscapeButton(QMessageBox::Close);
    	//int ret = msgBox.exec();
    	QVariant tempQ = QVariant(statusCodeV.toString().length());
    	msgBox.setText(tempQ.toString());
    	int ret = msgBox.exec();
    	
        // "200 OK" received?
        if (statusCodeV.toInt()==200)
            {
            // TODO: read data from QNetworkReply
            msgBox.setText("Successfull!...");
            int ret = msgBox.exec();
            
            QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes); // string
            ui.textEdit->setText(string);
            }
        // Some http error or redirect
        else
            {
            // TODO: 
            msgBox.setText("UnSuccessfull!...");
            int ret = msgBox.exec();
            }
            
        delete reply;
    
    	
    
    
    }
    
    void QTInternet::fetch_clicked(){
    
    	QMessageBox msgBox;
    	msgBox.setText("Fetch!...");
    	int ret = msgBox.exec();
    	QUrl url("http://www.google.com");
    	//QUrl url(ui.plEdit->text());
    	QNetworkReply* reply = netMan->get(QNetworkRequest(url));
    }
    Last edited by ltomuta; 2009-10-11 at 21:05. Reason: Made code section legible

Similar Threads

  1. HTTP Connection behaviour when 3G connection is lost (or being lost)
    By TwmD in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2010-01-27, 12:36
  2. how to know that network connection breaks during HTTP request
    By Ajmal in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2008-09-18, 11:40
  3. Simple http request
    By Christophe.A in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2008-06-11, 16:42
  4. Problem with HTTP POST
    By thathoo in forum Mobile Java General
    Replies: 2
    Last Post: 2006-12-18, 18:23
  5. Series 40 phones HTTP POST problem
    By jessicay in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2004-06-23, 01:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×