Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用Q_Declare_元类型声明无符号字符[]_C++_Qt_Qttest - Fatal编程技术网

C++ 使用Q_Declare_元类型声明无符号字符[]

C++ 使用Q_Declare_元类型声明无符号字符[],c++,qt,qttest,C++,Qt,Qttest,我正在尝试使用qtest设置一些单元测试,我想使用QFETCH 我正在测试以下功能: static std::vector<bool> FrameHandler::getBitsFromFrame(unsigned char* data, unsigned char length); 而且: On line `QTest::addColumn<unsigned char[]>("Tested");`, Type is not registered, please use

我正在尝试使用qtest设置一些单元测试,我想使用QFETCH

我正在测试以下功能:

static std::vector<bool> FrameHandler::getBitsFromFrame(unsigned char* data, unsigned char length);
而且:

On line `QTest::addColumn<unsigned char[]>("Tested");`, Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
第'QTest::addColumn(“Tested”);行上的
,类型未注册,请使用Q_DECLARE_元类型宏将其告知Qt的元对象系统
我认为这两个错误是相互关联的,所以我添加了
Q_DECLARE_元类型(unsigned char[])在类声明之前,但我得到以下结果:

qmetatype.h
中,应在“*”标记之前加“>”(第1695行)

是否可以将
无符号字符[]
声明到Qt的QMetaType系统? 谢谢

Q\u DECLARE\u元类型(T)类型T必须是可构造、可复制和可破坏的。 数组不符合此规则,但您可以创建包装器

struct Arr
{
    unsigned char arr[SIZE];
};
Q_DECLARE_METATYPE( Arr );

typedef std::数组TArr;
Q_声明_元类型(TArr);

但是有一个困难-大小,您必须声明它,或者只使用
无符号字符*
Yes。但在这种情况下,您必须保持指向某个位置的对象,以避免访问冲突。这是一个测试数据,所以它可以通过静态常量来实现。大概OP知道他在做什么,现在是为了避免越界访问。@arturx64您的答案看起来很合理,我会尽快尝试!
On line `QTest::addColumn<unsigned char[]>("Tested");`, Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
struct Arr
{
    unsigned char arr[SIZE];
};
Q_DECLARE_METATYPE( Arr );
typedef std::array<unsigned char, SIZE> TArr;
Q_DECLARE_METATYPE( TArr );