This step is very important because you don’t want to lose your object when the page is refreshed. This will ensure that the web view re-adds your object if the page ever gets refreshed.
Next, define the function that gets called when the page is loaded or refreshed:
In this example, I added the main window to the web view. You can add anything to the web view as long as it’s a class that inherits from QObject.
Q_INVOKABLE void doSomething();
It’s all that simple.