Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML Textinput
Forum Updated to NodeBB v4.3 + New Features

QML Textinput

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 5.2k Views 1 Watching
  • 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.
  • 1 Offline
    1 Offline
    143U
    wrote on last edited by
    #2

    User enters the value in text input field say some : 100
    Now I neeed to store this value in variable x, and make coressponding change in cpp document. Please help me with the idea and the code

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #3

      Hi Mohamed!

      did you already read this doc?
      http://doc-snapshot.qt-project.org/4.8/qtbinding.html

      its a good introduction about exchanging data between QML and C++!

      Rgds, Steven

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • 1 Offline
        1 Offline
        143U
        wrote on last edited by
        #4

        Yes, I did but this did not help me. Do you have an idea on how to go about with this.. Thanks in advance

        1 Reply Last reply
        0
        • 1 Offline
          1 Offline
          143U
          wrote on last edited by
          #5

          I have an idea on how to link the date but I need to get the user date from the textinput field which is a big barrier for me, am stuck with this for the past 10 days:(

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stevenceuppens
            wrote on last edited by
            #6

            I suggest to derive your C++ class from QObject, and add that class to the Declaratice view.

            @
            MyClass myClass; // <-- Create your class

            QDeclarativeView view;
            view.rootContext()->setContextProperty("myClass", &myClass); // <-- Add class to view

            view.setSource(QUrl::fromLocalFile("MyQml.qml"));
            view.show();
            @

            Within your C++ class, create a slot that accepts a QString as parameter,

            @
            class MyClass : public QObject
            {
            Q_OBJECT

            public slots:
            void cppSlot(const QString &value) {
            qDebug() << "Called the C++ slot with value:" << value;
            }
            };
            @

            from within QML, link your textinput to this slot

            @
            // MyItem.qml
            import QtQuick 1.0

            TextInput {
            id: item
            width: 100; height: 20

             onAccepted: myClass.cppSLot(item.text)
            

            }
            @

            This is a quick draft, but i hope this would make it more clear !?

            Rgrds, Steven

            Steven CEUPPENS
            Developer &#x2F; Architect
            Mobile: +32 479 65 93 10

            1 Reply Last reply
            0
            • 1 Offline
              1 Offline
              143U
              wrote on last edited by
              #7

              I just have to enter the value on the keyboard and this wil work??
              Regards,
              Mohd

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stevenceuppens
                wrote on last edited by
                #8

                i guess :) thats how i do it...

                Did you try it already this way?

                Steven CEUPPENS
                Developer &#x2F; Architect
                Mobile: +32 479 65 93 10

                1 Reply Last reply
                0
                • 1 Offline
                  1 Offline
                  143U
                  wrote on last edited by
                  #9

                  Thanks you Mr. Steven I got an idea now..

                  1 Reply Last reply
                  0
                  • 1 Offline
                    1 Offline
                    143U
                    wrote on last edited by
                    #10

                    Yes, I did give it a try before, but I did not include onAccepted attribute, is there any way we can make an UI where the user enters the data once he hits enter the Ui disappears, and takes it to the CPp window.

                    1 Reply Last reply
                    0
                    • 1 Offline
                      1 Offline
                      143U
                      wrote on last edited by
                      #11

                      any idea on how to make the changes in qml from cpp--

                      1 Reply Last reply
                      0
                      • 1 Offline
                        1 Offline
                        143U
                        wrote on last edited by
                        #12

                        [[blank-post-content-placeholder]]

                        1 Reply Last reply
                        0

                        • Login

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