Line edit &Enter button
-
How to give values to line edit by keyboard enter button ?
connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(handleLineEditValue())); void MainWindow::on_Increment_pushbutton_clicked() { handleLineEditValue(); value1 += 1000; ui->lineEdit->setText(QString::number(value1)); ui->lineEdit->setAlignment(Qt::AlignCenter); if(value1<9999) { QByteArray bytearray; bytearray.resize(1); bytearray[0]='#'; bytearray[1]='1'; bytearray[2]='P'; bytearray[3]='='; bytearray[4]='0'; bytearray[5]=QString::number(value1).toUtf8()[0]; bytearray[6]=QString::number(value1).toUtf8()[1]; bytearray[7]=QString::number(value1).toUtf8()[2]; bytearray[8]=QString::number(value1).toUtf8()[3]; bytearray[9]='!'; serial->write(bytearray); qDebug() << bytearray; } else { QByteArray bytearray; bytearray.resize(1); bytearray[0]='#'; bytearray[1]='1'; bytearray[2]='P'; bytearray[3]='='; bytearray[4]=QString::number(value1).toUtf8()[0]; bytearray[5]=QString::number(value1).toUtf8()[1]; bytearray[6]=QString::number(value1).toUtf8()[2]; bytearray[7]=QString::number(value1).toUtf8()[3]; bytearray[8]=QString::number(value1).toUtf8()[4]; bytearray[9]='!'; serial->write(bytearray); qDebug() << bytearray; } } void MainWindow::handleLineEditValue() { value1 = ui->lineEdit->text().toInt(); }
from this code increment operation works but If I give value of 5000 in line edit it accepts but position not changed and again clicked increment button value increased ie 6000 and position changed and how to correct this code?
-
-
@jsulm reference arm motor(position(increment ,decrement), step(increment ,decrement)) , polarizer motor(position(increment ,decrement), step(increment ,decrement), and sample arm motor(position(increment ,decrement), step(increment ,decrement))
-
@Rockerz
No idea what this answer means, to anyone but you maybe. You show code just manipulating what is in a text edit and/or sent to your serial device. If serial device is not acting as you expect and that is what you are reporting, it has nothing to do with a "line edit & Enter button", find out what you need to send and what you are actually sending. -
@Rockerz
I presume your bytearray is wrong, you can use much simpler code like that:QByteArray data1; data1.append("#1P="); int value=1200; data1.append(QString("%1").arg(value,5,10,QChar('0')).toLocal8Bit()); qDebug()<<QString(data1); QByteArray data2; value=10200; data2.append("#1P="); data2.append(QString("%1").arg(value,5,10,QChar('0')).toLocal8Bit()); qDebug()<<QString(data2);
"#1P=01200"
"#1P=10200" -