c++ - 错误 : no matching function for call to

标签 c++ qt

我收到这个错误:

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 类本身。在这两种情况下,它都失败了。我也不能给出它的非指针,因为 new 返回一个指针。

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

最佳答案

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

尝试这样的事情:

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

    int lol() {
        return 666;
    }
};

关于c++ - 错误 : no matching function for call to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7111442/

相关文章:

c++ - 没有#pragma comment lib 命令的 Unresolved external symbol 错误

c++ - 如何在 Windows 控制台中为特定像素着色

c++ - 在 C++ 中使用线程创建 QT gui?

c++ - QMediaPlayer - 即时修改音频

c++ - 读取没有定义的静态 const 数据成员的值 : what governs these rules?

c++ - 使用 boost C++ 单元测试套件测试非 fatal error 消息

c++ - 一次计算正弦和余弦

java - Qt:如何突出显示 QListWidget 中的重复项目? (qtjambi)

c++ - QLocale - 验证价格

c++ - Qt Automake 单独的include、ui、资源文件夹