开发者

How to get the whole HTML source code from some website in Qt? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学Go Closed 10 years ago.

I spent whole day to find a Qt code to get a source code from some website(e.g. www.google.com), but everything I found, it didn't work. So, please can someone post the code how to get the source code from website? (I am using Qt creator and I don't know nothing about slot connecting, so please write the code without the slot connecting(or whatever is this) if it is even possible.

EDIT: Here is the code:

project.pro

#-------------------------------------------------
#
# Project created by QtCreator 2011-01-02T21:40:52
#
#-------------------------------------------------

QT       += core gui
QT       += webkit network

TARGET = facebook
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

main.cpp

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

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

mainwindow.cpp

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

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->buttonBack->setText("");                                           /*******************************/
    ui->buttonForward->setText("");                                        /*       Clear text from       */
    ui->buttonReload->setText("");                                         /*         the buttons         */
    ui->buttonStop->setText("");                                           /*******************************/
    ui->buttonBack->setIcon( QApplication::style()->standardIcon(QStyle::SP_ArrowBack));            /*******************************/
    ui->buttonForward->setIcon( QApplication::style()->standardIcon(QStyle::SP_ArrowForward));      /*         Set an icons        */
    ui->buttonReload->setIcon( QApplication::style()->standardIcon(QStyle::SP_BrowserReload));      /*        on the buttons       */
    ui->buttonStop->setIcon( QApplication::style()->standardIcon(QStyle::SP_BrowserStop));          /*******************************/
    //QString htmlOfPage;
    /********    T    E    S    T    ********/

    //ui->browser->setHtml("<html><body>Test</body></html>");

    /********    T    E    S    T    ********/
}

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

void MainWindow::on_buttonBack_clicked()
{
    ui->browser->back();
}

void MainWindow::on_buttonForward_clicked()
{
    ui->browser->forward();
}

void MainWindow::on_buttonReload_clicked()
{
    ui->browser->reload();
}

void MainWindow::on_buttonStop_clicked()
{
    ui->browser->stop();
}

void MainWindow::on_browser_loadFinished(bool )
{
    //QWebView webview;
    //webview.setUrl (QUrl("http://www.google.com"));
    //QString s =  webview.page()->mainFrame()->toHtml();
    //htmlOfPage = ui->browser.page()->mainFrame()->toHtml();
}

I have a file mainwindow.h and mainwindow.ui too, but I think that nobody needs those files, so I didn't post them.


#include <QApplication>
#include <QDebug>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QIODevice>
#include <QUrl>


class MyClass : public QObject{

    Q_OBJECT

public slots:
    void onFinished() {
        QIODevice * content = static_cast<QIODevice*>(QObject::sender());
        qDebug() << content->readAll();
        content->deleteLater();
    }
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QNetworkAccessManager nam;
    MyClass obj;

    QNetworkReply * reply = nam.get(QNetworkRequest(QUrl("http://google.com")));
    QObject::connect(reply, SIGNAL(finished()), &obj, SLOT(onFinished()));

    app.exec();
}

#include "main.moc"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜