Qt 中Byte 类型 转换成 int 或者 qstring
我的程序是这样的。
void Dialog::readdata()其中如果没有QMessageBox::information(NULL, "","A message was received");这一句,程序酒会出现接收信息为空的警告。但是如果加上这句话,就没有问题。但是我不惜望出现这么一个提示框。
{
TPCANMsg msg;
TPCANTimestamp timestamp;
TPCANStatus result;
char strMsg[256];
QString Dataid, Datain=NULL;
QByteArray D;
do
{
// Check the receive queue for new messages
result = CAN_Read( m_PcanHandle,&msg,×tamp);
if(result == PCAN_ERROR_OK)
{
// Process the received message
QMessageBox::information(NULL, "","A message was received");
Dataid =QString::number(msg.ID, 16);
int temp=*(int*)msg.DATA;
Datain= QString::number(temp, 16);
ui->textEdit->setText("ID:"+Dataid+" Data:"+Datain);
}
else
{
// An error occurred, get a text describing the error and show it
// and handle the error
CAN_GetErrorText(result, 0, strMsg);
QString var = QString(QLatin1String(strMsg));
//QMessageBox::information(NULL, "",var);
// Here can be decided if the loop has to be terminated (eg. the bus
// status is bus-off)
}
}while((result & PCAN_ERROR_QRCVEMPTY) != PCAN_ERROR_QRCVEMPTY);
}