QObject :: connect没有匹配功能

时间:2013-06-18 16:40:07

标签: c++ qt connection qobject

chip_definition/Isrc/NLBChipDefinitionEditor.C:20: error: no matching function for call to `nlb::gui::chip_definition::ChipDefinitionEditor::connect(QAction*, const char*, nlb::gui::chip_definition::ChipDefinitionEditor* const, const char*)'

我从代码中收到此错误:

   qDebug() << dynamic_cast<QObject*>(this);
    connect(m_engine->actionRegister().actionAt(nlb::gui::base::ACTION_ID_CONTEXT_REMOVE_CHIP), SIGNAL(triggered(bool)), this, SLOT(onRemoveSelectedChips()));

错误表明this(ChipDefinitionEditor*)QObject*被评论时不是dynamic_cast而是connectChipDefinitionEditor当然来自QObject。怎么会发生这种情况?

1 个答案:

答案 0 :(得分:3)

Qt期望connect的参数属于QObject*类型。鉴于此形式的错误:

no matching function for call to `connect(SOMETYPE*, const char*, 
                                          SOMEOTHERTYPE*, const char*)'

编译器隐含地声明它没有指示SOMETYPESOMEOTHERTYPEQObject的信息,给出了该翻译单元所包含的内容。通常,只需包含SOMETYPE / SOMEOTHERTYPE的头文件,就可以为编译器提供确定SOMETYPE / SOMEOTHERTYPE继承自QObject所需的内容。在其他情况下(例如您的),您需要确保SOMETYPE / SOMEOTHERTYPE已动态转换为QObject

值得注意的是,当编译器有足够的信息用于一种类型而不是另一种类型时,错误消息会略有改变。例如,如果您修复了SOMETYPE但不是SOMEOTHERTYPE的错误,则错误消息会略有变化:

no matching function for call to `connect(QObject*, const char*, 
                                          SOMEOTHERTYPE*, const char*)'