我在将QWebEnginePage连接到fullScreenRequested方面有困难,我正在尝试以下方法,但这会导致错误
错误:“,”令牌连接之前的预期主表达式(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));
}
};请帮我解决这个问题。谢谢
发布于 2017-03-25 10:15:07
您的问题是信号/时隙连接以源对象和目标对象作为参数,并且混合了两种连接方式。
它要么
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*更好,或者更好的QString,就像使用Qt一样QWebEngineView* view=new QWebEngineView();最好在WebView构造函数中实例化它。this->是不可缺少的WebView(QObject* parent = nullptr, QString page = "https://google.com"):
QObject(parent),
home_page(page),
view(new QWebEngineView())
{
//...
}https://stackoverflow.com/questions/43014882
复制相似问题