当我使用此代码单击Quora提要中任何问题的链接时,链接不会打开,但不会打印"Hello"。你能告诉我我错在哪里吗?我很确定 quora 上的链接会发出OpenLinkInNewTab
信号。请帮忙,谢谢。
class WebView : public QObject {
void newTabRequested() {
std::cout<<"Hello"<<std::endl;
}
public:
char* home_page;
QAction* newTabAction=new QAction();
QWebEngineView* view=new QWebEngineView();
WebView(char* page=(char*)"https://google.com") {
this->home_page=page;
this->exitFullScreen->setShortcut(Qt::Key_Escape);
createWebView();
this->view->settings()
->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows,true);
this->newTabAction=this->view->pageAction(QWebEnginePage::OpenLinkInNewTab);
connect(this->newTabAction,&QAction::toggled,this,&WebView::newTabRequested);
}
void createWebView() {
this->view->load(QUrl(this->home_page));
}
};
我认为
问题是newTabRequested
不是一个插槽。尝试
class WebView : public QObject{
Q_OBJECT
private slots:
void newTabRequested(){
std::cout<<"Hello"<<std::endl;
}
// ...
}