0

I am trying to implement the displaying of a web page in Qt.I add one buttoon ,when clicked,update the new html content,and Re-execution the js,but when clicked 2 times,Popup execute 2 times,when clicked 3 times,Popup execute 3 times, I think, it add js to the html content many times. what should i do make the Popup execute 1 times? [I want to clear previous html content when click the button.but i don't know how to do ]

in .h . QWebEngineView *articleWebView;

in .cpp: articleWebView = new QWebEngineView();

in js. function abs() {alert("test");}

QString articleJS = readArticleJs ();

QString funcStr =  QString("\n abs(\"%1 \",\"%2\");").arg(highlightWords1).arg(highlightSentece1);
articleJS.append (funcStr);
this->articleWebView->page ()->runJavaScript (articleJS);
nisarg parekh
  • 413
  • 4
  • 23
  • It's unclear from the code you posted but probably upon the button click you repeatedly create new `QWebEngineViews` without removing the old ones. – Dmitry Jun 15 '19 at 17:41
  • in .cpp void ReadingQuestionAndArticleMainWindow::getclickNextSignalFromRMtoolMain() { articleWebView->setHtml ("test"); connect(this->articleWebView, &QWebEngineView::loadFinished,[=](){ setAticleDataWithQuestion(); }); } void ReadingQuestionAndArticleMainWindow::setAticleDataWithQuestion { qDebug()<<"====Test======"; QString articleJS = "abs()"; this->articleWebView->page ()->runJavaScript (articleJS ); } connect (this->readingTool,&RMtoolMain::toReadingQuestionAndArticleMainWindowSignalClickNext,this,&ReadingQuestionAndArticleMainWindow::getclickNextSignalFromRMtoolMain); – gg1999m882 Jun 16 '19 at 16:42
  • You should put this code into the question because within the comment it's really hard to read - there's no formatting or anything. But I managed to find out that you call `connect` each time `ReadingQuestionAndArticleMainWindow::getclickNextSignalFromRMtoolMain` runs. That explains the issue you observe - the connection to lambda is not a single-shot one, you don't need to re-establish it every time. Per current code each time the button is pressed you add more and more lambdas listening to the signal - that's why you get popup multiple times. You really need to connect the lambda only once. – Dmitry Jun 16 '19 at 17:42

0 Answers0