Search code examples
qtwindowqml

Create new window using QML


  MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                         acceptedButtons: Qt.LeftButton | Qt.RightButton
                         onEntered: Function.call(somefunc())
                         onExited: console.log("Mouse Exited");
                onClicked: {
                    Qt.quit();
                }
            }

How to create a new window using the function somefunc() when my mouse enters the Mouse Area. Is it possible?
I cannot find any way to integrate a C++ file into Qt so that I can use the function to create a new window.


Solution

  • Yes, it is possible to achieve what you want. C++ and QML can work together in some ways but none of them (as far as I know) involves embedding the C++ code into the QML code. Before going forward I recommend you to ask yourself the following:

    1. Why not defining the window itself in QML?
    2. Why not defining somefunc() in JavaScript, a language you can use in your QML file.