想在消息中显示每个字符的十六进制(如果可能的话,简单的方法,我知道我可以遍历字符并做到这一点):
typedef struct{
double dTime;
char cMessage[11];
} typeCanMessage;
typeCanMessage cmMessage1 = {4.5, {0xd2, 0xf1, 0xe0, 0xf1, 0xf1, 0xf1, 0xf1, 0x23, 0x23, 0x23, 0x23}};
QMessageBox *msgBox = new QMessageBox(0);
msgBox->setGeometry(QRect(QPoint(200,200),QSize(400,400)));
msgBox->setInformativeText(QString::number(cmMessage1.dTime, 'f', 8) + " "
+ QString::number(cmMessage1.cMessage, 'x')); // <-- something like this perhaps
msgBox->exec();
错误:“重载 'number(char[11], char)' 的调用不明确”
修改:
sprintf(cM, "%x", &cmMessage1.cMessage);
QMessageBox *msgBox = new QMessageBox(0);
msgBox->setGeometry(QRect(QPoint(200,200),QSize(400,400)));
msgBox->setInformativeText(QString::number(cmMessage1.dTime, 'f', 8) + " "
+ (QString)cM); // <-- something like this perhaps
msgBox->exec();
结果:bfb123d8 //错误
我想避免执行以下操作(循环或无循环):
sprintf(cM, "%X%X%X%X%X%X%X%X%X%X%X", cmMessage1.cMessage[0],
cmMessage1.cMessage[1],
cmMessage1.cMessage[2],
cmMessage1.cMessage[3],
cmMessage1.cMessage[4],
cmMessage1.cMessage[5],
cmMessage1.cMessage[6],
cmMessage1.cMessage[7],
cmMessage1.cMessage[8],
cmMessage1.cMessage[9],
cmMessage1.cMessage[10]);
循环:
for(int i = 0; i < 11; i++){
sprintf(cM + 2 * i, "%X", cmMessage1.cMessage[i]);
}