我正在创建一个图形用户界面应用程序,其中我有一个动态QComboBox。我已经使用QPointer来存储QComboBox *,这样当它被删除(在其他地方)时,我就可以避免出现悬空指针。尽管QPointer应该是一个带有到原始指针类型的转换操作符的智能指针,但当我将它传递给QObject::connect() (新样式)时,我会收到一个编译器错误。
示例:
QPointer<QComboBox> CMB_ItemType = new QComboBox;
connect(CMB_ItemType, &QComboBox::currentTextChanged, [&](const QString val){ui->TW_Contents->setCellWidget(nRow, 1, CMB_ItemContent);});编译器说:
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()来使其工作,但是为什么不自动使用转换运算符?
发布于 2016-10-26 17:30:40
我的测试变体运行良好:
QPointer<QLineEdit> le = new QLineEdit;
connect(le, &QLineEdit::textChanged, this, &QWidget::close);我觉得你的lambda有些问题。
https://stackoverflow.com/questions/40257434
复制相似问题