به دست آوردن محتوای یو ارال



  • سلام

    من میخواستم که سورس یک صفحه وب رو تو یه رشته داشته باشم
    این کدو نوشتم ولی کار نمیکنه
    heder
    @#include <QObject>
    #include <QNetworkReply>
    #include <QNetworkAccessManager>
    #include <QByteArray>
    class WebAccessor : public QObject
    {
    Q_OBJECT
    public:
    WebAccessor();
    void fetch(const QString &url);
    QNetworkAccessManager *netManager_;
    QString pageData_;
    void get();
    public slots:
    void replyFinished(QNetworkReply *reply);
    };
    @

    cpp:
    @
    #include "webaccessor.h"

    WebAccessor::WebAccessor(){
    netManager_ = new QNetworkAccessManager(this);
    connect(netManager_, SIGNAL(finished(QNetworkReply *)),
    this, SLOT(replyFinished(QNetworkReply *)));

    }

    void WebAccessor::fetch(const QString &url){
    netManager_->get(QNetworkRequest(QUrl(url)));
    }

    void WebAccessor::replyFinished(QNetworkReply *pReply){
    qDebug()<<"finished";
    QByteArray data = pReply->readAll();
    pageData_ = QString(data);
    }
    void WebAccessor::get(){

    qDebug()<<pageData_;

    }@

    نمی دونم مشکلش از کجاست
    چه راه دیگه ای هست که بشه سورس یه صفحه رو گرفت



  • p{direction:rtl; text-align:right}. سلام

    @void Widget::on_pushButton_clicked()
    {
    QNetworkAccessManager manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply
    )),
    this, SLOT(replyFinished(QNetworkReply*)));
    manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));
    }

    void Widget::replyFinished(QNetworkReply *e)
    {
    textEdit->setPlainText(e->readAll());
    }
    @



  • آقا ممنون
    دستت درد نکنه


Log in to reply
 

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