- void MainWindow::on_textEdit_textChanged()
- {
- ui->textEdit->disconnect();
- qDebug()<<"Enter timeout processing function\n";
- QString str =ui->textEdit->toPlainText();
- str.remove(QRegExp("\\s"));//移除空格
- if(str.length()%2==0)
- {
- QByteArray text;
- text=QByteArray::fromHex(str.toLatin1()); //获取文本框的字符串,转换成字流
- qDebug()<<text.data(); // returns 字符串
- str=text.toHex(' ');
- ui->textEdit->setText(str);
- qDebug()<<"text:"<<str; // 每两个字中间插入1个空格
- qDebug()<<"--------------------------------";
- ui->textEdit->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
- }
- connect(ui->textEdit,SIGNAL(textChanged()),this,SLOT(on_textEdit_textChanged()));
- }
上面是完整的代码
|