如何在C ++ / QT中打印结构的元素? [英] how to print elements of the struct in C++/QT?

查看:82
本文介绍了如何在C ++ / QT中打印结构的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印以下结构的TPCANMsg.ID和DATA





  typedef   struct  tagTPCANMsg 
{
DWORD ID; // 11/29位消息标识符
TPCANMessageType MSGTYPE; // 消息类型
BYTE LEN; // 消息的数据长度代码(0..8)
字节数据[< span class =code-digit> 8 ]; // 消息数据(DATA [0] .. DATA [7])
} TPCANMsg;



任何想法?

解决方案

要打印它,你必须了解数据类型的值是什么正在代表。最好为此编写转换器功能。



蓝图 - 示例:

  const   char  * TPCANMessageTypeToText( const  TPCANMessageType * typ){
if (* typ = 0x00){ // PCAN_MESSAGE_STANDARD
return PCAN消息是CAN标准帧(11位标识符);
}
// 其他所有
}



我找到的值此处


I want to print TPCANMsg.ID and DATA of following struct


typedef struct tagTPCANMsg
{
    DWORD             ID;      // 11/29-bit message identifier
    TPCANMessageType  MSGTYPE; // Type of the message
    BYTE              LEN;     // Data Length Code of the message (0..8)
    BYTE              DATA[8]; // Data of the message (DATA[0]..DATA[7])
} TPCANMsg;


Any idea?

解决方案

To print it you must understand what the values oft data types are representing. It is best to write converter function for that.

Blueprint-Example:

const char*  TPCANMessageTypeToText( const TPCANMessageType* typ ) {
  if( * typ = 0x00 ) { //PCAN_MESSAGE_STANDARD
    return "The PCAN message is a CAN Standard Frame (11-bit identifier)";
  }
//all the rest
}


The value I have found here.


这篇关于如何在C ++ / QT中打印结构的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆