0
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时会转换为 ok 。当然是来源于。这怎么可能发生?connectChipDefinitionEditorQObject

4

1 回答 1

3

Qt expects that the arguments to connect be of type QObject*. Given an error of this form:

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

The compiler is implicitly stating that it doesn't have information indicating that SOMETYPE and SOMEOTHERTYPE is a QObject given what has been included for that translation unit. Often times, simply including the header file for SOMETYPE/SOMEOTHERTYPE provides the compiler with what it needs to determine that SOMETYPE/SOMEOTHERTYPE inherits from QObject. In other cases (such as yours), you need to ensure that SOMETYPE/SOMEOTHERTYPE has been dynamically cast to a QObject.

It's also worth noting that when the compiler has adequate information for one type but not the other, the error message changes slightly. For example, if you fix the error for SOMETYPE but not SOMEOTHERTYPE, the error message changes slightly:

no matching function for call to `connect(QObject*, const char*, 
                                          SOMEOTHERTYPE*, const char*)'
于 2013-06-18T17:56:45.663 回答