c – 连接到派生类中的受保护插槽
发布时间:2020-12-16 03:47:45 所属栏目:百科 来源:网络整理
导读:这是基类中的声明的样子: protected: void indexAll(); void cleanAll(); 在派生类中,以下内容无法编译: indexAll(); // OKconnect(_timer,QTimer::timeout,this,FileIndex::indexAll); // ERRORconnect(_timer,SIGNAL(timeout()),SLOT(indexAll())); // O
这是基类中的声明的样子:
protected: void indexAll(); void cleanAll(); 在派生类中,以下内容无法编译: indexAll(); // OK connect(&_timer,&QTimer::timeout,this,&FileIndex::indexAll); // ERROR connect(&_timer,SIGNAL(timeout()),SLOT(indexAll())); // OK 我想使用connect的第一个变种,因为它做了一些编译时间检查.为什么这会返回错误: error: 'void Files::FileIndex::indexAll()' is protected void FileIndex::indexAll() ^ [...].cpp:246:58: error: within this context connect(&_timer,&FileIndex::indexAll); ^ 解决方法
“旧”样式语法有效,因为信号发射通过qt_static_metacall(..)运行,它是FileIndex的成员,因此具有受保护的访问权限.
‘new’样式语法确实有效,但for this reason不允许直接获取父类方法的地址.然而,它将采用indexAll()的“继承”地址,因此只需将代码更改为: connect(&_timer,&Derived::indexAll); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |