错误:没有匹配的函数调用 [英] error: no matching function for call to

查看:640
本文介绍了错误:没有匹配的函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个错误:

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();
}



我试过给一个新的实例 Eh Eh 类本身。在这两种情况下都失败。

I've tried giving a new instance of Eh and the Eh class itself. In both cases it fails. Also I can't give the non-pointer of it since new returns a pointer.

我的问题是:为什么是 Eh *& ; 而不是 Eh *

My question is this: why is it Eh*& and not Eh*?

推荐答案

addToJavaScriptWindowObject QObject * 作为其第二个参数。所以你需要有 Eh 继承自 QObject

addToJavaScriptWindowObject takes a QObject* as its second parameter. So you need to have Eh inherit from QObject.

尝试这样:

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

    int lol() {
        return 666;
    }
};

这篇关于错误:没有匹配的函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆