当我使用此代码在 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));
}
};