Hi,

I am trying to write a code so that when I press "1" it should map it and show a , b, or c according tot he timeout conditions from the previous key pressed.
Following is my code:

Qt Code:
  1. if((e->key() == Qt::Key_1) && ((target->objectName() == "textBox1") || (target->objectName() == "textBox2") || (target->objectName() == "textBox3") || (target->objectName() == "textBox4")))
  2. {
  3. int value;
  4. bool stat = connect(sameKey, SIGNAL(timeout()), this, SLOT(second()));
  5. qDebug()<<"connect returns "<< stat;
  6. sameKey->start(1000);
  7.  
  8. value = processKey(Qt::Key_1);
  9. qDebug()<<"value received from processKey is "<<value;
  10. if(value == 0)
  11. {
  12. if(target->objectName() == "textBox1")
  13. {
  14. QString temp = textBox1->toPlainText();
  15. temp.append("a");
  16. textBox1->setText(temp);
  17. }
  18. }
  19. else if(value == 1)
  20. {
  21. if(target->objectName() == "textBox1")
  22. {
  23. QString temp = textBox1->toPlainText();
  24. temp.append("b");
  25. textBox1->setText(temp);
  26. }
  27. }
  28. else if(value == 2)
  29. {
  30. if(target->objectName() == "textBox1")
  31. {
  32. QString temp = textBox1->toPlainText();
  33. temp.append("c");
  34. textBox1->setText(temp);
  35. }
  36. }
To copy to clipboard, switch view to plain text mode 

the process key function
Qt Code:
  1. int MainWindow::processKey(int keyCode)
  2. {
  3. // qDebug()<<"got the keycode as "<<keyCode;
  4. current_key = keyCode;
  5.  
  6. if((!timerFlag) && (current_key == prev_key))
  7. {
  8. qDebug("b4 timer stop");
  9. count++;
  10. if(count == 3)
  11. count = 0;
  12. sameKey->stop();
  13. }
  14. else
  15. {
  16. qDebug("in else");
  17. count = 0;
  18. timerFlag = 0;
  19. // sameKey->stop();
  20. }
  21.  
  22. prev_key = current_key;
  23. qDebug()<<"returning count as "<<count;
  24. return count;
  25. }
To copy to clipboard, switch view to plain text mode 

the update timer function
Qt Code:
  1. void MainWindow::second()
  2. {
  3. qDebug("in timer update slot.");
  4. sameKey->stop();
  5. timerFlag = 1;
  6. }
To copy to clipboard, switch view to plain text mode 

But the output I get when I press 1 twice simultaneously is "ab" and not just "b".
Please help me.
Thanks in advance.
- Charvi