qRegisterMetaType用法

Sri*_*kan 11 qt

  #include<QMetaType>

  typedef QList<int> IntList;

  qRegisterMetaType<IntList>("IntList");


error C2909: 'qRegisterMetaType': explicit instantiation of function template requires return type
Run Code Online (Sandbox Code Playgroud)

C2909说我需要定义

 template int qRegisterMetaType<IntList>("IntList");
Run Code Online (Sandbox Code Playgroud)

如果我像上面提到的那样定义,那么我得到以下错误

 error C2059: syntax error : 'string'
 warning C4667: 'int qRegisterMetaType(void)' : no function template defined that matches forced instantiation
Run Code Online (Sandbox Code Playgroud)

为什么我会收到此错误?

小智 11

"qRegisterMetaType"是一个函数.它必须出现在代码块中.