QT += webkitwidgets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include "ui_mainwindow.h" | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
myWebView = new QWebView; | |
ui->verticalLayout->addWidget(myWebView); | |
connect(myWebView, SIGNAL(loadFinished(bool)),this, SLOT(loadPageFinished(bool))); | |
QUrl url("https://www.google.co.jp/"); | |
myWebView->load(url); | |
myWebView->show(); | |
} | |
MainWindow::~MainWindow() | |
{ | |
delete ui; | |
} | |
/*ページの読み込み終了した時の処理*/ | |
void MainWindow::loadPageFinished(bool) | |
{ | |
qDebug() << "asd"; | |
QWebElementCollection elements = myWebView->page()->mainFrame()->findAllElements("a"); | |
foreach (QWebElement e, elements) { | |
// Process element e | |
QString hrefText = e.attribute("href");//リンクアドレス | |
QString plainText = e.toPlainText(); | |
qDebug() << hrefText; | |
qDebug() << plainText; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAINWINDOW_H | |
#define MAINWINDOW_H | |
#include <QMainWindow> | |
#include <QDebug> | |
#include <QWebView> | |
#include <QWebElementCollection> | |
#include <QWebFrame> | |
namespace Ui { | |
class MainWindow; | |
} | |
class MainWindow : public QMainWindow | |
{ | |
Q_OBJECT | |
public: | |
explicit MainWindow(QWidget *parent = 0); | |
~MainWindow(); | |
private: | |
Ui::MainWindow *ui; | |
QWebView *myWebView; | |
public slots: | |
void loadPageFinished(bool); | |
}; | |
#endif // MAINWINDOW_H |
0 件のコメント:
コメントを投稿