我无法将QWebEnginePage
与fullScreenRequested
联系起来,我正在尝试以下方式蚂蚁给出错误
main.cpp:58:错误:在'之前预期的primary-expression,'代币 connect(this-> view-> page(),SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)),& QWebEngineFullScreenRequest,SLOT(& QWebEngineFullScreenRequest :: accept()));
我的代码:
class WebView:public QObject{
public:
char* home_page;
QWebEngineView* view=new QWebEngineView();
WebView(char* page=(char*)"https://google.com"){
this->home_page=page;
createWebView();
this->view->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled,true);
connect(this->view->page(),SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)),&QWebEngineFullScreenRequest,SLOT(&QWebEngineFullScreenRequest::accept()));
}
void createWebView(){
this->view->load(QUrl(this->home_page));
}
QWebEngineView* returnView(){
return this->view;
}
void home(){
this->view->load(QUrl(this->home_page));
}
};
请帮我解决此问题。感谢
答案 0 :(得分:1)
您的问题是信号/插槽连接将源对象以及目标对象作为参数,并且您混合了两种连接方式。
它要么
connect(&src, &FirstClass::signalName, &dest, &SecondClass::slotName);
或者
connect(&src, SIGNAL(signalName(argType)), &dest, SLOT(slotName(artType)));
在你的情况下&QWebEngineFullScreenRequest
不是一个对象,而是你试图获取一个类的地址。您需要一个QWebEngineFullScreenRequest
类的实例来连接它。
正确的方式:
WebView(...)
{
//...
connect(this->view->page(), &QWebEnginePage::fullScreenRequested, this, &WebView::acceptFullScreenRequest);
}
private slots:
void acceptFullScreenRequest(QWebEngineFullScreenRequest request) {
request.accept();
}
其他一些评论:
char* page=(char*)"https://google.com"
,对于使用const char*
的文字更好,或者使用Qt时更好的QString QWebEngineView* view=new QWebEngineView();
最好在WebView
构造函数this->
是必要的WebView(QObject* parent = nullptr, QString page = "https://google.com"):
QObject(parent),
home_page(page),
view(new QWebEngineView())
{
//...
}