Post QNetworkAccessManager not found



  • Hi is that I'm creating a class and when I click on button shows nothing qDebug().
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "postgetservidor.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private slots:
    void abri();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(abri()));

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::abri()
    {
    PostGetServidor *amr = new PostGetServidor;

    amr->DoHttpGet();
    
    delete amor;
    

    }

    #ifndef POSTGETSERVIDOR_H
    #define POSTGETSERVIDOR_H

    #include <QObject>
    #include <QNetworkAccessManager>
    #include <QNetworkReply>
    #include <QByteArray>
    #include <QString>
    #include <QNetworkRequest>
    #include <QTimer>

    class PostGetServidor : public QObject
    {
    Q_OBJECT
    public:
    explicit PostGetServidor(QObject *parent = 0);
    ~PostGetServidor();
    void DoHttpGet();
    signals:

    public slots:
    void finished(QNetworkReply *reply);

    private:
    QNetworkAccessManager *nam;

    };

    #endif // POSTGETSERVIDOR_H

    #include "postgetservidor.h"

    PostGetServidor::PostGetServidor(QObject parent) :
    QObject(parent)
    {
    //QObject::connect(nam,SIGNAL(finished(QNetworkReply
    )),this,SLOT(finishedSlot(QNetworkReply*)));
    nam = new QNetworkAccessManager(this);
    connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(finished(QNetworkReply*)));

    }

    PostGetServidor::~PostGetServidor()
    {
    delete nam;
    }

    void PostGetServidor::finished(QNetworkReply *reply)
    {
    if(reply->error() == QNetworkReply::NoError)
    {
    qDebug() << "no erro" << reply->readAll();
    }
    else
    {
    qDebug() << reply->errorString();

    }
    

    }

    void PostGetServidor::DoHttpGet()
    {
    QUrl url("http://localhost/hola.php");
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    QString data="version=9219086fdffa30ac879568ee5c3sc0015&usuario=amorl";
    QByteArray postData;
    postData.append(data.toUtf8());

    if(postData.isEmpty() == true)
            {
            nam->get(request);
            }
    else
            {
            nam->post(request,postData);
            }
    

    }

    #include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    MainWindow w;
    
    w.show();
    return a.exec&#40;&#41;;
    

    }
    @

    (sierdzio) Edit: added code tags


  • Moderators

    Can you please elaborate on what is your problem / question?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.