gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:17:43 25 4
gpt4 key购买 nike

我收到这个错误:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com