首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用QPointer连接信号和插槽

使用QPointer连接信号和插槽
EN

Stack Overflow用户
提问于 2016-10-26 16:35:48
回答 1查看 862关注 0票数 0

我正在创建一个图形用户界面应用程序,其中我有一个动态QComboBox。我已经使用QPointer来存储QComboBox *,这样当它被删除(在其他地方)时,我就可以避免出现悬空指针。尽管QPointer应该是一个带有到原始指针类型的转换操作符的智能指针,但当我将它传递给QObject::connect() (新样式)时,我会收到一个编译器错误。

示例:

代码语言:javascript
复制
QPointer<QComboBox> CMB_ItemType = new QComboBox;
connect(CMB_ItemType, &QComboBox::currentTextChanged, [&](const QString val){ui->TW_Contents->setCellWidget(nRow, 1, CMB_ItemContent);});

编译器说:

代码语言:javascript
复制
     error: no matching function for call to 'EditRegionClass::connect(QPointer<QComboBox>&, void (QComboBox::*)(const QString&), EditRegionClass::addContent(QString, QString)::__lambda43)'
 connect(CMB_ItemType, &QComboBox::currentTextChanged, [&](const QString val){ui->TW_Contents->setCellWidget(nRow, 1, CMB_ItemContent);});
                                                                                                                                                    ^

我可以通过替换CMB_ItemType -> CMB_ItemType.data()来使其工作,但是为什么不自动使用转换运算符?

EN

回答 1

Stack Overflow用户

发布于 2016-10-26 17:30:40

我的测试变体运行良好:

代码语言:javascript
复制
QPointer<QLineEdit> le = new QLineEdit;
connect(le, &QLineEdit::textChanged, this, &QWidget::close);

我觉得你的lambda有些问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40257434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档