×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    Qt with PHP Server

    Hi,

    I have done a small application in Qt using code found at:

    http://wiki.forum.nokia.com/index.ph..._request_in_Qt

    My url is QUrl url("http://124.247.237.173/test/testPOST.php")

    Problem is when I hit URL http://124.247.237.173. I get sucessful reply.
    But When I use http://124.247.237.173/test/testPOST.php.
    I am unable to get reply .This url is tested and gives Hit as reply.

    This is the code:
    QNetworkReply* reply = nam->post(QNetworkRequest(url),myData);

    Can any one help me with this issue.Is there any problem in using Qt with PHP?.Or I am doing it wrong.Waiting for reply.

    Regards,
    Vishal

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

    Re: Qt with PHP Server

    Quote Originally Posted by vishalrocks101 View Post
    This is the code:
    QNetworkReply* reply = nam->post(QNetworkRequest(url),myData);
    This it not all the code

  3. #3
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    Re: Qt with PHP Server

    Quote Originally Posted by divanov View Post
    This it not all the code
    Hi,
    Thanks for reply ,, Sry Below is the Code:

    MyHttpEngine::MyHttpEngine(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MyHttpEngine)
    {

    QString username = "ABC";
    QByteArray myData(username.toUtf8(),username.length());

    nam = new QNetworkAccessManager(this);
    connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot(QNetworkRepl y*)));
    QUrl url("http://124.247.237.173/test/testPOST.php");
    QNetworkReply* reply = nam->post(QNetworkRequest(url),myData);

    }

    SLOT:....

    void MyHttpEngine::finishedSlot(QNetworkReply* reply)
    {
    if (reply->error() == QNetworkReply::NoError)
    {
    // read data from QNetworkReply here

    QByteArray bytes = reply->readAll();
    QString string(bytes); // string
    QMessageBox::information(this,"Info",bytes);
    QVariant cunt = string.count();
    QString count = cunt.toString();
    QMessageBox::information(this,"Info",count);

    }

    else
    {
    QMessageBox::information(this,"Error","Error Hitting Url");
    }


    }






    Regards,
    Vishal

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

    Re: Qt with PHP Server

    Well, probably it doesn't make any sense as there is nothing wrong with wiki. But this is sample application,
    which works for your case:

    Code:
    #include <QApplication>
    
    #include "netmanager.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        NetManager netManager;
        netManager.show();
    
        return a.exec();
    }
    Code:
    #ifndef NET_MANAGER_H
    #define NET_MANAGER_H
    
    #include <QNetworkAccessManager>
    #include <QNetworkReply>
    #include <QLabel>
    
    class NetManager : public QLabel
    {
        Q_OBJECT
    
    public:
        NetManager(QWidget *parent=0);
    
    private slots:
        void finished(QNetworkReply* reply);
    
    private:
        QNetworkAccessManager *nam;
    };
    
    #endif //NET_MANAGER_H
    Code:
    #include <QDebug>
    
    #include "netmanager.h"
    
    NetManager::NetManager(QWidget *parent)
        : QLabel(parent)
    {
        setFont(QFont("Nokia Sans", 35, QFont::Bold));
        setMinimumSize(200, 200);
    
        nam = new QNetworkAccessManager(this);
        connect(nam, SIGNAL(finished(QNetworkReply*)),
                this, SLOT(finished(QNetworkReply*)));
    
        QByteArray myData("ABC");
        nam->post(QNetworkRequest(QUrl("http://124.247.237.173/push%20it/actionworkerlogin.php?txtemail=abc&txtpwd=aaa")),
                  myData);
    }
    
    
    void NetManager::finished(QNetworkReply *reply)
    {
        if (reply->error() == QNetworkReply::NoError)
            setText(reply->readAll());
        else
            setText(reply->errorString());
    
        delete reply;
    }
    Last edited by divanov; 2010-03-04 at 12:53. Reason: minor stylistic change, update

  5. #5
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    Re: Qt with PHP Server

    hi,
    Divanov,Thanks for reply now its working fine for me after using your code ..

    Regards,
    Vishal

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

    Re: Qt with PHP Server

    The funniest thing is that my code is not different from wiki code and from your code.
    Last edited by divanov; 2010-09-29 at 12:17.

  7. #7
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    Re: Qt with PHP Server

    Hi, i'm starting with something similar. I have to request some php URL from my app to login, just like

    nam->post(QNetworkRequest(QUrl("http://124.247.237.173/push%20it/actionworkerlogin.php?txtemail=abc&txtpwd=aaa")),
    myData);

    After that, once mi app is logged in y need to request another php URL to get some data. Mi question is, could i just hit that other URL?
    Does QT handle all the PHP session stuff that handles a browser (I mean sendding the SSID and so)?

    Thanks!

Similar Threads

  1. XML onLoad with background http server problem
    By simonjuric in forum [Archived] Flash Lite on Nokia Devices
    Replies: 5
    Last Post: 2009-06-08, 16:47
  2. Mobile learning server / environment published
    By mikaset in forum News and Announcements
    Replies: 0
    Last Post: 2008-03-25, 20:50

Posting Permissions

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