WebContent inside a custom Widget
-
wrote on 18 Jun 2018, 05:45 last edited by
Hey,
As far as i know modern applications like discord, or skype(i think?) just use and browser integrated in their desktop application, and I'd like to try this with QT, but I'm kinda getting confused with all the QWeb stuff available.
My main goal is to display an js/html created chat(or whatever) inside an custom designed Widget. Which QT feature would work in this case?
Thanks
~Slei -
Hey,
As far as i know modern applications like discord, or skype(i think?) just use and browser integrated in their desktop application, and I'd like to try this with QT, but I'm kinda getting confused with all the QWeb stuff available.
My main goal is to display an js/html created chat(or whatever) inside an custom designed Widget. Which QT feature would work in this case?
Thanks
~Slei@Slei Take a look at http://doc.qt.io/qt-5/qtwebengine-index.html
-
wrote on 18 Jun 2018, 06:12 last edited by
Hi @Slei ,
You should also refer this link: http://doc.qt.io/qt-5/qjsengine.html
and as @jsulm mentioned link that also you have to refer. -
wrote on 18 Jun 2018, 06:21 last edited by
http://doc.qt.io/archives/qt-5.5/qtwebenginewidgets-index.html I've look at the QWebEngineView already, but this seems to always create a seperate windows, for me the best would be to have this as ui element(the webcontent) inside my custom widget, but so far I couldn't really see which part of the whole WebEngine stuff i would need for this, even with the Whole c++ Browser example its kinda hard to get it.
-
http://doc.qt.io/archives/qt-5.5/qtwebenginewidgets-index.html I've look at the QWebEngineView already, but this seems to always create a seperate windows, for me the best would be to have this as ui element(the webcontent) inside my custom widget, but so far I couldn't really see which part of the whole WebEngine stuff i would need for this, even with the Whole c++ Browser example its kinda hard to get it.
@Slei It should not create a window. How do you use QWebEngineView? Can you show your code?
-
wrote on 18 Jun 2018, 06:36 last edited by
oh i think i forgot to pass my widget this ptr to the WebEngineView, now it seems to work
-
wrote on 18 Jun 2018, 06:43 last edited by
@Slei Ok then mark Unsolved to Solved at top of page.
-
wrote on 18 Jun 2018, 08:28 last edited by Slei
still got some questions:
I was able to call c++ stuff from js with QWebChannel, the only thing that doesn't work is C++ calling JS functions, somehow it always says
js: Uncaught ReferenceError: jsFun is not defined
[24368:11572:0618/102139.247:INFO:CONSOLE(1)] "Uncaught ReferenceError: jsFun is not defined", source: (1)
[24368:11572:0618/102139.247:INFO:CONSOLE(1)] "Uncaught ReferenceError: jsFun is not defined", source: (1)<html> <body> <script type="text/javascript"> function jsFun() { window.alert(1337); } </script> <script type="text/javascript" src="./qwebchannel.js"></script> <script type="text/javascript"> new QWebChannel(qt.webChannelTransport, function (channel) { // now you retrieve your object var JSobject = channel.objects.Widget; var obj = { "testObject": "yes" }; JSobject.ShowPopup(10); }); </script> Hello </body> </html>
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) , m_wev(new QWebEngineView(this)) { ui->setupUi(this); QWebChannel* channel = new QWebChannel(m_wev); m_wev->page()->setWebChannel(channel); channel->registerObject(QString("Widget"), this); m_wev->load(QUrl("file:///C:/Users/dr/Documents/QT-Client-Playground/WebContent/WebContentTest/index.html")); m_wev->show(); // HERE EXECUTE JS FUNCTION m_wev->page()->runJavaScript("jsFun();",[this](const QVariant &v) { qDebug()<<v.toString();}); }
-
wrote on 18 Jun 2018, 09:30 last edited by Slei
calling jsFun() directly in js works fine, but somehow it doesn't work from c++, not sure when the call from c++ happens, since it just can't find the function definition
-
wrote on 18 Jun 2018, 12:34 last edited by
ok seems like i've called the js function too early.
using it in loadFinished from QWebEngineView works fine
1/10