Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 2 Support (Qt 5) › Using WebChannel

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19531

    Łukasz

    Hi, I’ m trying to use WebChannel in my V-play app to call QML methods and sginals from remote server, but I don’t know how to do that on Android. WebEngineView is not supported. This is simplified example:

    import Felgo 3.0
    import QtQuick 2.0
    import QtWebView 1.0
    import QtWebChannel 1.0
    
    App {
        NavigationStack {
    
            Page {
                title: qsTr("Main Page")
    
    
    
                Rectangle {
                    id: rect
                    width: 50
                    height: 50
                    color: "red"
    
                    function someMethod() {
                        console.log("in QML");
                    }
                }
    
                WebView {
                    id: webView
                    anchors.top: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.bottom: parent.bottom
                    url: "http://buddyintour.com/someFile.html"
    
                    WebChannel {
                        registeredObjects: [rect];
                    }
                }
            }
    
        }
    }

    someFile.html placed on my server. There is qwebchannel.js in the same folder.

    <!DOCTYPE html>
    <html>
      <head>
        <script src="qwebchannel.js"></script>
      </head>
      <body> 
        <script>
        
            if(typeof qt == "undefined") console.log("qt is not ok"); 
            else {
                var channel_obj = new QWebChannel(qt.webChannelTransport, function(channel){
                    var rect = channel.objects.rect;
                    rect.someMethod()
                });
            }
    
        </script>
      </body>
    </html>

     

    I suspect that connection I want to realize is not as easy as I think :/. Do you have any ideas how to make my QML objects visible from html?

    #19536

    Günther
    Felgo Team

    Hi Lukasz,

    I never tried WebChannel so far – but it is usable for Felgo in the same manner as for general Qt/QML apps. There’s a WebChannel example available here: http://doc.qt.io/qt-5/qtwebchannel-examples.html

    You can try the example and browse the code to see how everything should be set up. If you can run the example, but Qt does not support some of the required features on mobiles (Android, iOS), the same goes for Felgo as well.

    Best,
    Günther

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded