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. How do I send Key Event from C++ to QML TextInput Item in Qt 5.2 ?
Forum Update on Monday, May 27th 2025

How do I send Key Event from C++ to QML TextInput Item in Qt 5.2 ?

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 3.7k 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.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #1

    How do I send Key Event from C++ to QML TextInput Item in Qt 5.2 ?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      I'm sure you have QMLViewer object in C++. This is used for launching the QML file. Use this as destination object.

      QtQuick2ControlsApplicationViewer w;

      You can do

      QApplication::postEvent(&w,new QKeyEvent(.....))

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aabc
        wrote on last edited by
        #3

        Can I send it directly to the TextInput ?

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          If this is the focused object, it will be sent to TextInput only.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aabc
            wrote on last edited by
            #5

            And if its not ?

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              If not we need to look at the issue. There may be other focused elements in the UI. What is the issue you are facing when you do this ?

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aabc
                wrote on last edited by
                #7

                I have pointer to the QML TextInput in C++ and I want to send it a Key event (simulate keyboaed) while it may not be focused

                1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  if you have pointer to TextInput use the post event as I suggested

                  QApplication::postEvent(pointerToTextInput,new QKeyEvent(…..))

                  If you give the sample code it helps us to look/analyze if you have any issue.

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  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