title: Fudging QWebEngine to run Javascript code 'synchronously'
body: <p>I am using <code>QWebEngine</code> and I would like to run some Javascript synchronously! Or at least pretend to. So I came up with an ol' classic, using <code>QEventLoop</code> to wait. I call this code from my <code>QWebEngineView</code> derived class:</p>
  
  <pre><code>void MyView::doSomething()
  {
      QEventLoop loop;
  
      const QString jsCode = "console.log('hi from javascript!');";
      page()-&gt;runJavaScript(jsCode,[&amp;](const QVariant&amp;)
      {
          qDebug() &lt;&lt; "script done!";
          loop.quit();
      });
  
      qDebug() &lt;&lt; "calling loop.exec()";
      loop.exec();
      qDebug() &lt;&lt; "finished loop.exec()";
  }
  </code></pre>
  
  <p>However this does not work as the lambda is never executed. Regardless of whether or not this is a complete hack (it is), I'm curious as to why it doesn't work.</p>
  
  <p>And in the spirit of this being a complete hack, is there a "better" way to accomplish what I'm trying to do? </p>
  
  <p>Thanks!</p>