×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    request and receive the response using the same QHttp

    Hello all,

    i am developing an application in Symbian S60 5th edition using qt.

    I need help ,please help me how do i solve my problem.

    Problem1:

    I need to send data to server.In my server one .php file is there which is

    responsible taking data (let say x) that is sent by Qhttp request and fetching

    data from databse according to(x) and return to my application let say (y)

    using QHTTP.

    So kindly tell me how do i solve this problem using Qhttp and QHttpRequestHeader


    This is my code :

    url->setPath("http://www.fgtpl.com/fugenx1/public_html/smartphone/insert.php");
    QMessageBox::information(this, tr("HTTP"),tr("in side function: %1.").arg(url->path()));
    QHttpRequestHeader header("GET",url->path());
    header.setValue("Host",url->host());
    QHttp::ConnectionMode mode = url->scheme().toLower() =="https" ? QHttp::ConnectionModeHttps :QHttp::ConnectionModeHttp;
    http->setHost(url->host(), mode,80);
    xmldata.open(QBuffer::ReadWrite);
    getRequestId = http->request(header);
    Last edited by shaktiqt123; 2010-03-18 at 12:36. Reason: add code to review

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: request and receive the response using the same QHttp

    For new applications, it is recommended to use QNetworkAccessManager and QNetworkReply, as those classes possess a simpler, yet more powerful API and a more modern protocol implementation.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Thanks den for your reply,

    Then please tell me how do i send a request to my .php page(let x) which is in

    my server using QNetworkAccessManager and get a response from that page.Response

    should be a some xml pattern.

    Please help me to solve this problem.

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Hi all ,

    How do i send a data through post to my webserver file like (xx.php) Using QNetworkAccessManager.I am able to run a file(xx.php) but i can not able to send data to xx.php file through QNetworkAccessManager.

    Please guide me SIR.........

  5. #5
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: request and receive the response using the same QHttp

    You could search for QNetworkAccessManager keyword in the forums and/or wiki. For example:
    http://discussion.forum.nokia.com/fo...01&postcount=4

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Thank you danill,

    now i am able to get connect with my .php file which is present in server and it return a data in the form of xml .

    And i get it in my QByteArray.but i read character by character from QByteArray.

    So please help me :

    How do i parse these xml file from QBytearray using QXmlStreamReader.

    Please help me to solve these problem.

  7. #7
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: request and receive the response using the same QHttp

    Check default Qt examples under XML section
    http://qt.gitorious.org/qt/qt/trees/master/examples/xml

  8. #8
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Hi danill,

    Thank you for your reply ,i am success what you gave me but i face one problem.

    when i run directly this program,its working fine.

    But when i create a object of class(let Say class MallList where QnetworkaccessManager connection available) in my Class (let say XXX)
    and try to execute its Finished slot is not called.so i can not get the server side data.

    Please help me to solve this problem.

  9. #9
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: request and receive the response using the same QHttp


  10. #10
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Hi thanks for ur reply Danill,

    Yes now that example works fine,now i can get response as a .xml file format
    data and it store in QNetworkReplay *reply.and i get those data by reply->readAll().Like below

    QByteArray by;
    by=reply->readAll();
    QXmlStreamReader xml;
    xml.addData(by);

    Now my data is in Xml format as i store in QXmlStreamReader objects.

    And When i Parse i got all Results fine.

    But The problem is that i store data in QStringList and display in Qwidget.
    Maximum 100 data i can store in QStringList But if More Than 100 data is coming
    it is not able to showing data .


    So Please help me how do i temporary store 1000 of data which is coming from server in the formate of .xml and can also showing in a QListWidget

    Please help me to solve this problem.

  11. #11
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: request and receive the response using the same QHttp

    Quote Originally Posted by shaktiqt123 View Post
    But The problem is that i store data in QStringList and display in Qwidget.
    Maximum 100 data i can store in QStringList But if More Than 100 data is coming
    it is not able to showing data.
    Could you please elaborate on this? How do you show data? What exactly is preventing you from storing 101st data?

  12. #12
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Hi thanks again for reply me

    In Below my .cpp and .h file is there. i got the data from server and put it in XmlStreamReader's object,then after i parse the .xml data and store the data(e.g:- mall lists in side a QStringList )i try with 100 data its working but when it 200 its not working.

    I create a class ShopLocator.Inside ShopLocator Class i create a object of MallList Class

    1.

    ml = new MallList;

    After that in side MallList constructor QNetworkAccessManager object is created and it connect with server using post method and get all data from server.And store in a StringList.

    Then i fetch the QStringList in side the ShopLocator and assign that to another QStringList ,
    just next to ml= new MallList ;

    Like
    2.

    QStringList Stringlist_Mallnames_Temp = ml->Stringlist_Mallnames;

    Then After i fetch the data of Stringlist_Mallnames_Temp and put inside a QListWidget.

    Like

    3.

    foreach (QString str_mallName, Stringlist_Mallnames_Temp)
    {
    mallListwidgetitem = new QListWidgetItem(QIcon(":/mall-icon.png"),str_mallName, mallListwidget);
    mallListwidget->insertItem(index_mallLwi,mallListwidgetitem);
    index_mallLwi = index_mallLwi+1;
    }

    But it does not showing any thing.




    MallList.cpp


    #include "MallList.h"
    #include "iostream.h"
    #include <QtGui/QWidget>
    #include <qstringlist.h>
    #include<qhttp.h>
    #include<qurl.h>
    #include <QtNetwork>
    #include <QtGui/QMessageBox>
    #include <QHttpRequestHeader>
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <QNetworkReply>

    MallList::MallList(QWidget *parent)
    : QWidget(parent)
    {
    url= new QUrl;
    manager = new QNetworkAccessManager(this); connect(manager,SIGNAL(finished(QNetworkReply*)),SLOT(downloadFinished(QNetworkReply*)));
    QByteArray myData("ABC");
    manager->post(QNetworkRequest(QUrl("http://www.fgtpl.com/fugenx1/public_htmlsmartphone/mallList.php")),myData);

    }

    /******************************************************************************
    * Function Name :downloadFinished
    * Author :Shakti sagar patnaik
    ******************************************************************************/

    void MallList::downloadFinished(QNetworkReply *reply)
    {
    if (reply->error() == QNetworkReply::NoError)
    {
    by=reply->readAll();

    }
    QXmlStreamReader xml;
    xml.addData(by);
    while (!xml.atEnd())
    {
    if (xml.isStartElement() && xml.name() == "mall_list")
    {
    QXmlStreamAttributes attrs = xml.attributes();
    MallName = attrs.value("ml_mallname");
    Stringlist_Mallnames << MallName.toString();
    if (MallName.isEmpty())
    {
    xml.readNext();
    continue;
    }
    }
    else if(xml.isEndElement() && xml.name() == "city_lists")
    {
    return;
    }
    xml.readNext();
    }
    }
    MallList::~MallList()
    {

    }

    MallList.h

    #ifndef MALLLIST_H
    #define MALLLIST_H

    #include <QtGui/QWidget>
    #include "ui_MallList.h"
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QLabel>
    #include <QtXml/QXmlStreamReader>
    #include <qstringlist.h>
    class QHttp;
    class QHttpResponseHeader;
    class QUrl;
    class QBuffer;
    class MallList : public QWidget
    {
    Q_OBJECT

    public:
    MallList(QWidget *parent = 0);
    QStringList Stringlist_Mallnames;
    ~MallList();
    private slots:
    void downloadFinished(QNetworkReply *reply);

    private:
    //Ui::MallListClass ui;
    QHttp *http;
    QUrl *url;
    QBuffer xmldata;
    QByteArray by;
    int getRequestId;
    QNetworkAccessManager *manager;
    QStringRef MallName;


    };

    #endif // MALLLIST_H

  13. #13
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Hi danill

    As per our discussion i describe all these things ,Please help me how do i

    solve my problem.

  14. #14
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: request and receive the response using the same QHttp

    Try to use device directly:
    Code:
    QXmlStreamReader xml(reply);
    while (!xml.atEnd())
    {
       ...
    }

  15. #15
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Re: request and receive the response using the same QHttp

    Thank you daniill,

    if i used this code ,the xml parsing is not working at all.I tested well ,so please help me how do i solve this problem.

    QXmlStreamReader xml(reply);
    while (!xml.atEnd())
    {
    /*********Parsing here*************/

    }

Similar Threads

  1. Simple HTTP GET request
    By raasoftware in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2009-08-26, 06:35
  2. SIP content type
    By hlothman in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-05-17, 09:26
  3. Receive uncomplete HTTP response
    By apitoman in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2004-03-24, 16:15
  4. Replies: 1
    Last Post: 2003-07-10, 07:34
  5. Can't receive response from servlet
    By satmovi in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-06-24, 02:17

Posting Permissions

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