QByteArray::fromHex(hex_str);报错form_para.cpp:342:68: No viable conversion from 'QString' to 'const QByteArray' qbytearray.h:181:5: candidate constructor not viable: no known conversion from 'QString' to 'const char *' for 1st argument qbytearray.h:189:12: candidate constructor not viable: no known conversion from 'QString' to 'QByteArray &&' for 1st argument qbytearray.h:463:12: candidate constructor not viable: no known conversion from 'QString' to 'QByteArrayDataPtr' for 1st argument qbytearray.h:524:20: candidate constructor not viable: no known conversion from 'QString' to 'const QByteArray &' for 1st argument qbytearray.h:405:67: passing argument to parameter 'hexEncoded' here
时间: 2023-12-24 21:02:11 浏览: 122
Qt基础开发之QString与QByteArray详细用法与区别及QString QByteArray互转
根据您提供的信息,这个错误是因为您使用了不同类型的参数。函数QByteArray::fromHex()需要一个十六进制字符串作为输入,而您传递了一个QString类型的参数,导致编译器无法将其转换为QByteArray类型。您需要将QString类型的参数转换为QByteArray类型的十六进制字符串,然后再将其传递给函数QByteArray::fromHex()。您可以使用QString的toUtf8()函数将QString转换为QByteArray类型的十六进制字符串,然后再将其传递给QByteArray::fromHex()函数。例如:
QString hex_str = "616263";
QByteArray hex_data = QByteArray::fromHex(hex_str.toUtf8());
阅读全文