Convert char* to uint8_t

后端 未结 4 734
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 02:30

I transfer message trough a CAN protocol.

To do so, the CAN message needs data of uint8_t type. So I need to convert my char* to ui

4条回答
  •  情书的邮戳
    2020-12-18 02:52

    char * is a pointer, not a single character. It is possible that it points to the character you want.

    uint8_t is unsigned but on most systems will be the same size as a char and you can simply cast the value.

    You may need to manage the memory and lifetime of what your function returns. This could be done with vector< unsigned char> as the return type of your function rather than char *, especially if toUtf8() has to create the memory for the data.

    Your question is totally ambiguous.

    ui->canDataModifiableTableWidget->item(6,3)->text().toUtf8().data();
    

    That is a lot of cascading calls. We have no idea what any of them do and whether they are yours or not. It looks dangerous.

提交回复
热议问题