# C++ function exposed to QML

**URL:** <https://discuss.px4.io/t/c-function-exposed-to-qml/26450>\
**Category:** Development\
**Created:** [March 4, 2022, 8:16am UTC](https://discuss.px4.io/t/c-function-exposed-to-qml/26450 "2022-03-04T08:16:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amith\_R](https://discuss.px4.io/user_avatar/discuss.px4.io/amith_r/32/10206_2.png) [@Amith\_R](https://discuss.px4.io/u/Amith_R)\
**Post date:** [March 4, 2022, 8:16am UTC](https://discuss.px4.io/t/c-function-exposed-to-qml/26450/1 "2022-03-04T08:16:57Z")

</div>

Hello QGC developers,  
I am trying to create a new window in AnalyzeTools option, along with MavlinkInspector , vibration and everything. I have written C++ backend with Q\_INVOKABLE functions and also window QML .

```auto
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.2
import QtCharts 2.3

import QGroundControl 1.0
import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Controllers 1.0
import QGroundControl.ScreenTools 1.0

AnalyzePage {
    id: CustomPage
    headerComponent: headerComponent
    pageComponent: pageComponent
    pageDescription: qsTr(" Application User Interface.")
    allowPopout: true

       
    property int curCompID: 0
    property real maxButtonWidth: 0
    property real _margin: ScreenTools.defaultFontPixelWidth
    property real _butttonWidth: ScreenTools.defaultFontPixelWidth * 30

    

        RowLayout {
            width: availableWidth
            height: availableHeight

            Connections {
                target: CustomController
            }

            Column {
                spacing: _margin
                Layout.alignment: Qt.AlignTop | Qt.AlignLeft
                QGCButton{
                    // enabled:    
                    text: qsTr("Launch App")
                    width: _butttonWidth
                    onClicked: {
                        CustomController.launch()
                    }

                }

                QGCButton{
                    // enabled:
                    text: qsTr("Stop App")
                    width: _butttonWidth
                    onClicked: {
                        CustomController.stop()
                    }
                }
            }
        }
    }

}

```

C++ Code. CustomController.h

```auto
// Controller for CustomPage.qml
class CustomController : public QObject{

    Q_OBJECT

    public:
        CustomController(void);
        

        Q_INVOKABLE void launch ();
        Q_INVOKABLE void stop ();
    
    signals:   

    // private slots:  

    private:
        bool _launched;
        Vehicle* _vehicle;
        UASInterface* _uas;
        QTimer _timer;

        void _sendLauncherMessage (uint8_t launch , uint8_t msg_type , uint8_t error_type);
        
};

```

In cpp file there are definitions for launch and stop functions mentioned above.  
I have modified the CMakeLists.txt and also QGCApplication.cc to add

```auto
qmlRegisterType<CustomController> (kQGCControllers, 1 ,0, "CustomController");

```

This is throwing a error

```auto
 TypeError: Property 'launch' of object [object Object] is not a function.

```

Any possible reason why C++ functions are not exposed to QML here ?  
I am very new to QT QML development . Any help would be appreciated .Thanks.

---

<div class="post-metadata">

**Author:** ![Amith\_R](https://discuss.px4.io/user_avatar/discuss.px4.io/amith_r/32/10206_2.png) [@Amith\_R](https://discuss.px4.io/u/Amith_R)\
**Post date:** [March 4, 2022, 9:12am UTC](https://discuss.px4.io/t/c-function-exposed-to-qml/26450/2 "2022-03-04T09:12:16Z")

</div>

I had to create a instance of CustomController in qml file. It worked after that.
