Thank you very much, now it is working as expected.

Best Regards

> Am 21.03.2016 um 15:48 schrieb Aleksey Yermakov <jp.kura...@gmail.com>:
> 
> Hi,
> 
> You don't have to inject QWebChannel.js every time if you use 
> QWebEngineScriptCollection in your QWebEngineProfile. Here is a sample code 
> from my project:
> 
> const char s_qWebChannelAdditionalScript[] = "new 
> QWebChannel(qt.webChannelTransport, function(channel) {"
>                                              "  window.exported_object = 
> channel.objects.exported_object;"
>                                              "});";
> 
> QWebEngineProfile *WebEngineView::prepareProfile()
> {
>     QWebEngineProfile *profile = new QWebEngineProfile("Profile", this);
> 
>     ...
> 
>     // Preparing qwebchannel.js for injection
>     QFile qWebChannelJsFile(":/qtwebchannel/qwebchannel.js");
> 
>     if(! qWebChannelJsFile.open(QIODevice::ReadOnly)) {
>         MY_ERROR("Failed to load qwebchannel.js with error: " + 
> qWebChannelJsFile.errorString());
>     } else {
>         QByteArray qWebChannelJs = qWebChannelJsFile.readAll();
> 
>         qWebChannelJs.append(QString(s_qWebChannelAdditionalScript));
> 
>         QWebEngineScript script;
> 
>         script.setSourceCode(qWebChannelJs);
>         script.setName("qwebchannel.js");
>         script.setWorldId(QWebEngineScript::MainWorld);
>         script.setInjectionPoint(QWebEngineScript::DocumentCreation);
>         script.setRunsOnSubFrames(false);
> 
>         profile->scripts()->insert(script);
>     }
> 
>     return profile;
> }
> 
> Don't forget to create your QWebEnginePage with this profile instead of 
> default one.
> 
> Cheers,
> Aleksey
> 
>> On Sun, Mar 20, 2016 at 9:30 PM, NoRulez <noru...@me.com> wrote:
>> Hello,
>> 
>> Did I have to inject QWebChannel and for example JQuery every time before or 
>> after I call setUrl()/load() to QWebEngineView or only once?
>> 
>> Because the jquery event for loading a site is only called once and if 
>> loaded then it has the previous url:
>> 
>> $(window).load(function () {
>>     alert('page is loaded');
>>     alert(window.location.href);
>> });
>> 
>> Thanks in advance
>> 
>> Best Regards
>> 
>> _______________________________________________
>> QtWebEngine mailing list
>> qtwebeng...@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/qtwebengine
> 
> 
> 
> -- 
> Aleksey Yermakov
> 
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to