문제

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*)'

Im getting this error from the code:

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

Error states that this(ChipDefinitionEditor*) is not QObject* but dynamic_cast casts ok when connect is commented. ChipDefinitionEditor is derived from QObject of course. How could this happen?

도움이 되었습니까?

해결책

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*)'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top