2011-08-18 239 views
0

我收到此錯誤:錯誤:沒有匹配函數調用

main.cpp:31: error: no matching function for call to 'QWebFrame::addToJavaScriptWindowObject(QString, Eh*&)' 
candidates are: void QWebFrame::addToJavaScriptWindowObject(const QString&, QObject*) 

這是源代碼:

#include <string> 
#include <QtGui/QApplication> 
#include <QWebFrame> 
#include <QWebView> 
#include <QGraphicsWebView> 
#include <QWebPage> 
#include "html5applicationviewer.h" 

class Eh 
{ 
    int lol() 
    { 
     return 666; 
    } 
}; 

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

    Html5ApplicationViewer viewer; 
    viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto); 
    viewer.showExpanded(); 
    viewer.loadFile(QLatin1String("html/index.html")); 

    QWebPage *page = viewer.webView()->page(); 
    QWebFrame *frame = page->mainFrame(); 

    Eh *s = new Eh(); 

    frame->addToJavaScriptWindowObject(QString("test"), s); 

    return app.exec(); 
} 

我試過給人EhEh一個新的實例課本身。在這兩種情況下都失敗了。我也不能給它的非指針,因爲new返回一個指針。

我的問題是這樣的:爲什麼它Eh*&而不是Eh*

回答

1

addToJavaScriptWindowObjectQObject*作爲其第二個參數。所以你需要從QObject繼承Eh

嘗試這樣:

class Eh : public QObject { 
    Q_OBJECT 
public: 
    Eh(QObject *parent = 0) : QObject(parent) { 
    } 

    int lol() { 
     return 666; 
    } 
}; 
+0

所以,問題不在於'&'字? – Tower

+0

@Evan Teran:我認爲OP的Q不是關於爲什麼錯誤,而是爲什麼錯誤的具體錯誤信息。 –

+0

不,不應該是問題。 –

相關問題