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. [SOLVED] QKeyPress - Simulating key press
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QKeyPress - Simulating key press

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.9k 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.
  • M Offline
    M Offline
    maximus
    wrote on 13 Mar 2015, 16:49 last edited by maximus
    #1

    I'm trying to simulate a key press on a lineEdit, but nothing is writing inside the lineEdit..

    I call this slot with a button press :

    locationEdit->setFocus();
    
    QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_A, Qt::NoModifier);
    QApplication::sendEvent(locationEdit, key_press);
    
    QKeyEvent *key_release = new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_A, Qt::NoModifier);
    QApplication::sendEvent(locationEdit, key_release);
    

    Solved with :
    locationEdit->setFocus();
    QTest::keyClick(locationEdit, Qt::Key_A);

    Awesome QTest lib, !


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Talha Celik
      wrote on 11 May 2020, 07:35 last edited by
      #2

      i try

      mainwindow.h
      #include<QtTest/QtTest>
      
      my_project.pro
      Qt += testlib
      

      then i get include __cdecl ... exception.

      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