Qt拾遗
You need to enable support for console applications in order to use the stdin, stdout and stderr streams at the console. To do this, add the following declaration to your application's project file:
CONFIG += console
意思就是说如果你想用Qt写控制台程序,需要在工程文件里加上这么一句: CONFIG += console
qRegisterMetaType()
qRegisterMetaType<MyClass>("MyClass");
当需要在自定义的类中连接信号与槽,就需要此函数告诉qt元数据系统,此类需要有默认的构造函数、复制构造函数以及析构函数
Q_DECLARE_METATYPE(Type)
一般用在自定义类的类定义体外面,同样需要有默认的构造函数、复制构造函数以及析构函数
开发文档里有这样一句:Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. Note that if you intend to use the type in queued signal and slot connections or in QObject's property system, you also have to callqRegisterMetaType() since the names are resolved at runtime.
信号与槽
要把信号成功连接到槽或者另一个信号,它们的参数必须具有相同的顺序和相同的类型。

浙公网安备 33010602011771号