我正在创建一个 GUI 应用程序,其中有一个动态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()但为什么不自动使用转换运算符?