Quantcast
Channel: Qt DevNet forums: Qt WebKit
Viewing all articles
Browse latest Browse all 542

get QObject with javascript failed!

$
0
0
mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H   #include <QMainWindow>   namespace Ui { class MainWindow; }   class MainWindow : public QMainWindow {     Q_OBJECT     public:     explicit MainWindow(QWidget *parent = 0);     ~MainWindow();     Q_INVOKABLE QObjectList  all();     Q_INVOKABLE QObject* get(); private:     Ui::MainWindow *ui;     QObjectList objects; private slots:       void addToJavaScriptWindowObject(); };   #endif // MAINWINDOW_H         #include "mainwindow.h" #include "ui_mainwindow.h" #include <QtWebKit> #include <QWebFrame>   MainWindow::MainWindow(QWidget *parent) :     QMainWindow(parent),     ui(new Ui::MainWindow) {     ui->setupUi(this);     QWebSettings::globalSettings()->setAttribute( QWebSettings::DeveloperExtrasEnabled,true);       QObject::connect(this->ui->webView->page()->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(addToJavaScriptWindowObject()));     //connect(this->ui->WV_Work->page()->mainFrame(),SIGNAL(loadFinished(bool)),this,SLOT(addToJavaScriptWindowObject()));       //this->ui->webView->load(QUrl::fromLocalFile("D:/kuaipan/workspalce/projects/Zeus/forbid.html"));     //th }   MainWindow::~MainWindow() {     delete ui; } void MainWindow::addToJavaScriptWindowObject() {      this->ui->webView->page()->mainFrame()->addToJavaScriptWindowObject("QObject",this);      //this->ui->webView->page()->mainFrame()->evaluateJavaScript("console.log(QObject);"); } QObjectList MainWindow::all() {     //QObjectList  ret;       return this->objects; } QObject* MainWindow::get() {     return this; } In Web Inspector’s console ,i input “ QObject.all() “,but it return >QObject.all() Error: cannot call all(): unknown type `QObjectList’ line: 2 message: “cannot call all(): unknown type `QObjectList’” stack: “all@[native code]↵eval code↵eval@[native code]↵evaluate@[native code]↵_evaluateOn↵_evaluateAndWrap↵evaluate” proto: Error >

Viewing all articles
Browse latest Browse all 542

Trending Articles