Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Add text in textarea inside class
Forum Updated to NodeBB v4.3 + New Features

Add text in textarea inside class

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MrErfanM Offline
    MrErfanM Offline
    MrErfan
    wrote on last edited by A Former User
    #1

    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)
    {
        ui->txt->appendPlainText(Number);
    }
    

    But I'm lost in Qml
    Please guide me
    tnaks...

    J.HilkJ 1 Reply Last reply
    0
    • MrErfanM MrErfan

      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)
      {
          ui->txt->appendPlainText(Number);
      }
      

      But I'm lost in Qml
      Please guide me
      tnaks...

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

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

      this

      onNumberChanged: myTextArea.text = myTextArea.text + Number
      

      doesn't work for you?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • MrErfanM Offline
        MrErfanM Offline
        MrErfan
        wrote on last edited by
        #3

        Thanks for the answer, where do I use it?

        J.HilkJ 1 Reply Last reply
        0
        • MrErfanM MrErfan

          Thanks for the answer, where do I use it?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @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
          
          Rectangle{
              id:root
               property int number: 0
               onNumberChanged: myText.text = myText.text  + " " + number
          
              Timer{
              interval: 1000
              repeat: true
              running: true
              onTriggered: number = number +1
              }
          
             Text{
              id:myText
              anchors.fill: parent;
              font.pixelSize: 20
              horizontalAlignment: Qt.AlignHCenter
              verticalAlignment:  Qt.AlignVCenter
            }
          
          }
          

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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • MrErfanM Offline
            MrErfanM Offline
            MrErfan
            wrote on last edited by MrErfan
            #5

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

            MyClass::MyClass(QObject *parent) : QObject(parent)
            {
                mThread = new MyThread(this);
                connect(mThread,SIGNAL(NumberChanged(QString,int)),this,SLOT(onNumberChanged(QString,int)));
            }
            
            public slots:
                void onNumberChanged(QString,int);
            void MyClass::onNumberChanged(QString Number,int num)
            {
                //Send Number from myclass to qml textedit
            }
            
            1 Reply Last reply
            0
            • ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by ODБOï
              #6

              Hello, see this : http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
              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 :

              MyClass{
                 onNumberChanged : txEdit.text += number
              }
              TextEdit{
                id: txEdit
              }
              

              You can also embed c++ object into QML; see here : http://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html // I think this is what you need
              Using this you have nothing to do
              //main.cpp

              MyClass obj;
              engine.rootContext()->setContextProperty("myObject",&obj)
              ```;
              //main.qml
              
              TextEdit{
                 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
              }
              

              LA

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved