I'm new using Qt and I'm having some troubles with it.
I'm doing a simple terminal application and I need to disable the buttons for a few seconds after they are selected.
I'm doing something like this:
void MainWindow::on_readcard_clicked(){
this->setEnabled(false);
//Send Command
QString commandString = "";
commandString.append('1');
commandString.append("\n");
QByteArray commandArray = commandString.toLocal8Bit();
serial->write(commandArray);
//Read Card
QByteArray data = serial->readLine(12);
QString dataString = 0;
dataString.append(data);
ui->cardnumber->setText(dataString);
dataString.clear();
data.clear();
QByteArray saldo = serial->readAll();
QString saldoString = 0;
saldoString.append(saldo);
ui->balance->setText(saldoString);
saldoString.clear();
saldo.clear();
this->setEnabled(true);}
I need this because if someone press the button twice before it finished processing the first tap I will get a "crazy" array with lots of trash. I also tried use "waitForBytesWritten" and "waitForReadyRead" but it hasn't blocked the connection until everything was processed.
Regards
Try with QTimer::SingleShot() :
this->setEnabled(false);
QTimer::singleShot(2000, this, SLOT(enableMyButton()));
// you code
void enableMyButton()
{
this->setEnabled(true);
}
It'll enable the button 2secs after the call
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.