Add text in textarea inside class

  • hi
    I want to add some value to the Textarea control inside a function cpp class.
    In the widgets project, it was very easy to do inside the function.

    void MyClass::onNumberChanged(QString Number,int num)

    But I'm lost in Qml
    Please guide me

  • Moderators

    @MrErfan I'm not quite sure what the problem is:


    onNumberChanged: myTextArea.text = myTextArea.text + Number

    doesn't work for you?

  • Thanks for the answer, where do I use it?

  • Moderators

    @MrErfan said in add text in textarea inside class:

    Thanks for the answer, where do I use it?

    Well you've been very vague with your description: so a quick example:

    import QtQuick 2.9
         property int number: 0
         onNumberChanged: myText.text = myText.text  + " " + number
        interval: 1000
        repeat: true
        running: true
        onTriggered: number = number +1
        anchors.fill: parent;
        font.pixelSize: 20
        horizontalAlignment: Qt.AlignHCenter
        verticalAlignment:  Qt.AlignVCenter

    Edit: fixed typo: font.size: 20 =>font.pixelSize: 20

  • I want to create numbers that within the class MyClass,
      Send to TextEdit (qml)

    MyClass::MyClass(QObject *parent) : QObject(parent)
        mThread = new MyThread(this);
    public slots:
        void onNumberChanged(QString,int);
    void MyClass::onNumberChanged(QString Number,int num)
        //Send Number from myclass to qml textedit

  • Hello, see this :
    to create your own QML Type "MyClass" with ' qmlRegisterType<MyClass>("io.qt.myClass", 1, 0, "MyClass"); '

    then you can create a MyClass{ } Item in qml and bind properties :

       onNumberChanged : txEdit.text += number
      id: txEdit

    You can also embed c++ object into QML; see here : // I think this is what you need
    Using this you have nothing to do

    MyClass obj;
       text : "your text" +  myObject.myQPrperty  // it will update automatical
       //using this way, variables must be QProperties and Methods must be QINVOKABLES to use from QML


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.