不好意思,我粘贴错了。
void MyComTool::manualCom_Sent()
{
QString user_input;
char *to_sent = new char[10240];
QChar *to_sent_tmp = new QChar[10240];
char sent_buf[2];
int b;
qint64 char_count;
user_input = comSentTextEdit->toPlainText();
to_sent = user_input.toAscii().data();
to_sent_tmp = user_input.data();
char_count = 0;
already_sent_times++;
if(!sent_hex_model)
{
//10.27//while (!to_sent_tmp->isNull())
//10.27//{
//10.27// ++to_sent_tmp;
//10.27// ++char_count;
//10.27//}
//char_count += 1;
sent_byte_counter +=myCom->write(to_sent);
myCom->waitForBytesWritten(-1);
comReceiveLabel->setNum (sent_byte_counter);
}
else
{
while (!to_sent_tmp->isNull())
{
b= (int)*to_sent;
sprintf(sent_buf, "%x", b);
hex_to_sent[char_count] = sent_buf[0];
hex_to_sent[char_count + 1] = sent_buf[1];
++to_sent_tmp;
++to_sent;
++char_count;
++char_count;
if(char_count >= 10240)
{
char_count = 0;
QMessageBox warningBox(this);
QString mypix;
mypix = ":/erroring.png";
QPixmap img(mypix);
warningBox.setIconPixmap(mypix);
warningBox.setWindowTitle(tr("错误"));
warningBox.setText(tr("发送数据过长!"));
warningBox.exec();
break;
}
}
sent_byte_counter += myCom->write(hex_to_sent, char_count);
myCom->waitForBytesWritten(-1);
comReceiveLabel->setNum (sent_byte_counter);
}
sentTimesClearLabel->setNum(already_sent_times);
delete [] to_sent;
delete [] to_sent_tmp;
}
这样还是不行。