QTimer::timeout()‘ is protected

实验 5 定时器和随机数(实验来源QT开源社区)

在这里插入图片描述
编译不通过。报错:QTimer::timeout()’ is protected问题。

原因分析:上述代码使用了QT5中新增加的关联方式,对connect()函数进行了重载,指定信号和槽两个参数时不用再使用SIGNAL()和SLOT()宏,并且槽函数不再必须是使用slots关键字声明的函数,而可以是任意能和信号关联的成员函数,因此将QT5中进行了重载的函数在QT4中使用,自然会报错。

[static] QMetaObject::Connection QObject::connect( const QObject *sender, PointerToMemberFunction signal, const QObject *receiver,PointerToMemberFunction method,                                    Qt::ConnectionType type = Qt::AutoConnection)

修改如下:
在这里插入图片描述
重新编译,问题解决。

猜你喜欢

转载自blog.csdn.net/CXYLVCHF/article/details/111522788
今日推荐