[Interest] Handle frames and web forms with QWebEngine
NoRulez
norulez at me.com
Tue Jan 5 23:54:03 CET 2016
I played a little bit with JavaScript and QWebChannel but I can't get it to work (I'm not familiar with JavaScript) which means that I tried to figure out which frame is created and trigger a signal from within JavaScript.
i think the parsing stuff is easier with regex in c++.
Could someone please help me to handle iframes correctly with QWebEngine.
I think those guys who has desired to replace QWebKit with QWebEngine should see the problem.
Thanks in advance
Best Regards
> Am 02.12.2015 um 10:36 schrieb NoRulez <norulez at me.com>:
>
> If someone is interested. I found a solution which avoid the use of QWebEngine/QWebChannel and JavaScript stuff and is a lot more easy and straight forward to use.
>
> connect(m_pWebEngineView, &QWebEngineView::loadFinished, [=]() {
> m_pWebEngineView->page()->runJavaScript("window.frames[\"MyFrame\"].document.body.innerHTML", [=](const QVariant &var) {
> const QString content = var.toString();
> // Parse the content with QRegularExpression
> // Here the following options are useful: QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption
> });
> });
>
> Best regards
>
>> Am 27.11.2015 um 09:48 schrieb Koehne Kai <Kai.Koehne at theqtcompany.com>:
>>
>>
>>
>>> -----Original Message-----
>>> From: NoRulez [mailto:norulez at me.com]
>>> Sent: Friday, November 27, 2015 9:35 AM
>>> To: Koehne Kai <Kai.Koehne at theqtcompany.com>
>>> Cc: Qt Project MailingList <interest at qt-project.org>
>>> Subject: Re: [Interest] Handle frames and web forms with QWebEngine
>>>
>>> This is not my tree, it's a simple webpage/webform. But it seems that the new
>>> "webengine" can't handle simple tasks like this.
>>
>> I think I already mentioned several approaches to do this.
>>
>>> I don't think that the following statement is too complex:
>>> document.getElementsByTagName('input')
>>
>> The statement itself is not complex. What it returns might be too complex for a simple transformation into a QVariant, though.
>>
>> Regards
>>
>> Kai
>>
>>> Best regards
>>>
>>>>> Am 25.11.2015 um 13:08 schrieb Koehne Kai
>>>> <Kai.Koehne at theqtcompany.com>:
>>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: NoRulez [mailto:norulez at me.com]
>>>>> Sent: Tuesday, November 24, 2015 2:37 PM
>>>>> To: Koehne Kai <Kai.Koehne at theqtcompany.com>
>>>>> Cc: Qt Project MailingList <interest at qt-project.org>
>>>>> Subject: Re: [Interest] Handle frames and web forms with QWebEngine
>>>>>
>>>>> No one?
>>>>>
>>>>> Isn't it supported to return simple objects?
>>>>
>>>> The code that does the transformation can be found in
>>> web_contents_adapter.cpp, function fromJSValue():
>>>>
>>>> http://code.woboq.org/qt5/qtwebengine/src/core/web_contents_adapter.cp
>>>> p.html
>>>>
>>>> Not sure how the JS representation of your tree is.
>>>>
>>>> A possible workaround might be to serialize the data structures, and return a
>>> JSON string (e.g. by using JSON.stringify()).
>>>>
>>>> Regards
>>>>
>>>> Kai
>>>>
>>>>> Best Regards
>>>>>
>>>>>
>>>>>> Am 19.11.2015 um 17:29 schrieb NoRulez <norulez at me.com>:
>>>>>>
>>>>>> I tried to use m_pWebEngineView->page()->runJavaScript() after the
>>>>>> site is
>>>>> loaded, but it returns QVariant(QVariantMap, QMap()) for most of the time.
>>>>>>
>>>>>> It seems that it can handle only simple queries like
>>>>>> "document.title" but not for
>>>>> example "window.frames['MyFrame].document.forms[0].elements".
>>>>>> With which I expect a list of maps or similar to get the form elements.
>>>>>>
>>>>>> Best Regards
>>>>>>
>>>>>>> Am 18.11.2015 um 16:40 schrieb Koehne Kai
>>>>> <Kai.Koehne at theqtcompany.com>:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: NoRulez [mailto:norulez at me.com]
>>>>>>>> Sent: Wednesday, November 18, 2015 12:20 PM
>>>>>>>> To: Koehne Kai <Kai.Koehne at theqtcompany.com>
>>>>>>>> Cc: Qt Project MailingList <interest at qt-project.org>
>>>>>>>> Subject: Re: [Interest] Handle frames and web forms with
>>>>>>>> QWebEngine
>>>>>>>>
>>>>>>>> Is there an example for such approach?
>>>>>>>
>>>>>>> Probably not for your specific request, but there's the 'fancybrowser'
>>>>> example that shows how to inject JavaScript:
>>>>>>>
>>>>>>> https://doc-snapshots.qt.io/qt5-5.6/qtwebengine-webenginewidgets-fa
>>>>>>> nc
>>>>>>> ybrowser-example.html
>>>>>>>
>>>>>>> We recently also just added a 'markdowneditor' example
>>>>>>> demonstrating the
>>>>> use of QWebChannel:
>>>>>>>
>>>>>>> https://doc-snapshots.qt.io/qt5-5.6/qtwebengine-webenginewidgets-ma
>>>>>>> rk
>>>>>>> downeditor-example.html
>>>>>>>
>>>>>>> Regards
>>>>>>>
>>>>>>> Kai
>>>>>>>
>>>>>>>
>>>>>>>>>> Am 18.11.2015 um 10:12 schrieb Koehne Kai
>>>>>>>>> <Kai.Koehne at theqtcompany.com>:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> -----Original Message-----
>>>>>>>>>> From: Interest [mailto:interest-bounces at qt-project.org] On
>>>>>>>>>> Behalf Of NoRulez
>>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> What is the preferred way to handle web forms (iterate over it
>>>>>>>>>> like QWebCollection does in QWebKit), search for frames by name
>>>>>>>>>> and get notified when a frame is created? (Was a signal in
>>>>>>>>>> QWebKit)
>>>>>>>>>
>>>>>>>>> The general approach is to load/inject JavaScript into the page
>>>>>>>>> that takes care
>>>>>>>> of this, and communicates with the C++ world either by return
>>>>>>>> value, or QWebChannel.
>>>>>>>>>
>>>>>>>>> Hope this helps,
>>>>>>>>>
>>>>>>>>> Kai
>>>>>> _______________________________________________
>>>>>> Interest mailing list
>>>>>> Interest at qt-project.org
>>>>>> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list