Charvi
12th July 2012, 10:49
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:
if((e->key() == Qt::Key_1) && ((target->objectName() == "textBox1") || (target->objectName() == "textBox2") || (target->objectName() == "textBox3") || (target->objectName() == "textBox4")))
{
int value;
bool stat = connect(sameKey, SIGNAL(timeout()), this, SLOT(second()));
qDebug()<<"connect returns "<< stat;
sameKey->start(1000);
value = processKey(Qt::Key_1);
qDebug()<<"value received from processKey is "<<value;
if(value == 0)
{
if(target->objectName() == "textBox1")
{
QString temp = textBox1->toPlainText();
temp.append("a");
textBox1->setText(temp);
}
}
else if(value == 1)
{
if(target->objectName() == "textBox1")
{
QString temp = textBox1->toPlainText();
temp.append("b");
textBox1->setText(temp);
}
}
else if(value == 2)
{
if(target->objectName() == "textBox1")
{
QString temp = textBox1->toPlainText();
temp.append("c");
textBox1->setText(temp);
}
}
the process key function
int MainWindow::processKey(int keyCode)
{
// qDebug()<<"got the keycode as "<<keyCode;
current_key = keyCode;
if((!timerFlag) && (current_key == prev_key))
{
qDebug("b4 timer stop");
count++;
if(count == 3)
count = 0;
sameKey->stop();
}
else
{
qDebug("in else");
count = 0;
timerFlag = 0;
// sameKey->stop();
}
prev_key = current_key;
qDebug()<<"returning count as "<<count;
return count;
}
the update timer function
void MainWindow::second()
{
qDebug("in timer update slot.");
sameKey->stop();
timerFlag = 1;
}
But the output I get when I press 1 twice simultaneously is "ab" and not just "b".
Please help me.
Thanks in advance.
- Charvi
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:
if((e->key() == Qt::Key_1) && ((target->objectName() == "textBox1") || (target->objectName() == "textBox2") || (target->objectName() == "textBox3") || (target->objectName() == "textBox4")))
{
int value;
bool stat = connect(sameKey, SIGNAL(timeout()), this, SLOT(second()));
qDebug()<<"connect returns "<< stat;
sameKey->start(1000);
value = processKey(Qt::Key_1);
qDebug()<<"value received from processKey is "<<value;
if(value == 0)
{
if(target->objectName() == "textBox1")
{
QString temp = textBox1->toPlainText();
temp.append("a");
textBox1->setText(temp);
}
}
else if(value == 1)
{
if(target->objectName() == "textBox1")
{
QString temp = textBox1->toPlainText();
temp.append("b");
textBox1->setText(temp);
}
}
else if(value == 2)
{
if(target->objectName() == "textBox1")
{
QString temp = textBox1->toPlainText();
temp.append("c");
textBox1->setText(temp);
}
}
the process key function
int MainWindow::processKey(int keyCode)
{
// qDebug()<<"got the keycode as "<<keyCode;
current_key = keyCode;
if((!timerFlag) && (current_key == prev_key))
{
qDebug("b4 timer stop");
count++;
if(count == 3)
count = 0;
sameKey->stop();
}
else
{
qDebug("in else");
count = 0;
timerFlag = 0;
// sameKey->stop();
}
prev_key = current_key;
qDebug()<<"returning count as "<<count;
return count;
}
the update timer function
void MainWindow::second()
{
qDebug("in timer update slot.");
sameKey->stop();
timerFlag = 1;
}
But the output I get when I press 1 twice simultaneously is "ab" and not just "b".
Please help me.
Thanks in advance.
- Charvi