Java Script failed to create QtQuick 2.5 object



  • I am creating QT object in Java script & emitting signal from JavaScript to QML Slot.

    My work Environment : Qt 5.8 MSVC2015 64bit, Windows 7 64 bit.

    Java Script code :

    
       var internalQmlObject = **Qt.createQmlObject('import QtQuick 2.5; QtObject{ signal someSignal(int value) }', Qt.application, 'InternalQmlObject')**;
        function runNow(){
            internalQmlObject.someSignal(42);
        }
    

    Code of QML :

    import QtQuick 2.5
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    import QtWebEngine 1.4
    import "testJava.js" as Helper
    
    
         ApplicationWindow {
            width: 1024
            height: 750
            visible: true
        
            WebEngineView {
                id: webEngine
                anchors.fill: parent
                url: "qrc:/TestPage.html"
        
                function someSlot(v) {
                    console.log("Signal received " + v);
                }
        
                onLoadingChanged: {
                    Helper.internalQmlObject.someSignal.connect(someSlot);
                }
            }
        }
    

    But Java Script failed to create QtQuick 2.5 object:

    Application log :
    D:\task\QT_Test\build-testURL-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\debug\testURL.exe...

    js: Uncaught ReferenceError: Qt is not defined

    [4492:5796:0427/113341:INFO:CONSOLE(1)] "Uncaught ReferenceError: Qt is not defined", source: qrc:/testJava.js (1)

    you can find my code

    Any suggestion why JavaScript failed to identify QT?



  • you can find my code

    I found the issue, in HTML page, I am loading testJava.js, which causing this issue : <head> <script type="text/javascript" src="testJava.js"></script> </head>

    But still why it should have an issue ?


Log in to reply