Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. WebContent inside a custom Widget
Forum Updated to NodeBB v4.3 + New Features

WebContent inside a custom Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 958 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Slei
    wrote on 18 Jun 2018, 05:45 last edited by
    #1

    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

    J 1 Reply Last reply 18 Jun 2018, 06:00
    0
    • S Slei
      18 Jun 2018, 05:45

      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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Jun 2018, 06:00 last edited by
      #2

      @Slei Take a look at http://doc.qt.io/qt-5/qtwebengine-index.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Prince_0912
        wrote on 18 Jun 2018, 06:12 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Slei
          wrote on 18 Jun 2018, 06:21 last edited by
          #4

          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.

          J 1 Reply Last reply 18 Jun 2018, 06:30
          0
          • S Slei
            18 Jun 2018, 06:21

            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.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 18 Jun 2018, 06:30 last edited by
            #5

            @Slei It should not create a window. How do you use QWebEngineView? Can you show your code?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Slei
              wrote on 18 Jun 2018, 06:36 last edited by
              #6

              oh i think i forgot to pass my widget this ptr to the WebEngineView, now it seems to work

              P 1 Reply Last reply 18 Jun 2018, 06:43
              0
              • S Slei
                18 Jun 2018, 06:36

                oh i think i forgot to pass my widget this ptr to the WebEngineView, now it seems to work

                P Offline
                P Offline
                Prince_0912
                wrote on 18 Jun 2018, 06:43 last edited by
                #7

                @Slei Ok then mark Unsolved to Solved at top of page.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Slei
                  wrote on 18 Jun 2018, 08:28 last edited by Slei
                  #8

                  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();});
                  
                  
                  }
                  
                  
                  
                  
                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Slei
                    wrote on 18 Jun 2018, 09:30 last edited by Slei
                    #9

                    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

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Slei
                      wrote on 18 Jun 2018, 12:34 last edited by
                      #10

                      ok seems like i've called the js function too early.
                      using it in loadFinished from QWebEngineView works fine

                      1 Reply Last reply
                      0

                      1/10

                      18 Jun 2018, 05:45

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved