[英]Qt - No matching function to call to connect
I have this error when I tried to call connect.当我尝试调用 connect 时出现此错误。
E:\\GraphTool\\graphscene.cpp:7: error: no matching function for call to 'GraphScene::connect(QObject*&, void (MainWindow:: )(Mode), GraphScene , void (GraphScene::*)(Mode))' QObject::connect(parent, &MainWindow::changedMode, this, &GraphScene::setMode); E:\\GraphTool\\graphscene.cpp:7: 错误:没有匹配的函数调用 'GraphScene::connect(QObject*&, void (MainWindow:: )(Mode), GraphScene , void (GraphScene::*)(Mode) ))' QObject::connect(parent, &MainWindow::changedMode, this, &GraphScene::setMode);
I called connect in graphscene.cpp我在 graphscene.cpp 中调用了 connect
GraphScene::GraphScene(QObject *parent) : QGraphicsScene (parent), mode(NAV) {
QObject::connect(parent, &MainWindow::changedMode, this, &GraphScene::setMode);
}
The GraphScene class : GraphScene 类:
class GraphScene : public QGraphicsScene {
Q_OBJECT
public:
GraphScene(QObject *);
void mousePressEvent(QGraphicsSceneMouseEvent*);
public slots:
void setMode(Mode m);
private:
Mode mode;
}
The MainWindow class :主窗口类:
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
public slots:
void actionTriggered(QAction *action);
signals:
void changedMode(Mode newMode);
private:
Ui::MainWindow *ui;
QActionGroup* modesGroup;
GraphScene *scene;
};
I emit the signal here, I don't know if that have anything to do with it :我在这里发出信号,我不知道这是否与它有关:
void MainWindow::actionTriggered(QAction *action){
QString actionText = action->text() ;
if(actionText == "Navigation"){
emit changedMode(NAV);
}
else if (actionText == "Add node") {
emit changedMode(ADD_NODE);
}
else if (actionText == "Delete node") {
emit changedMode(DEL_NODE);
}
}
I found many other answers on SO related but I couldn't fix it.我在 SO 相关上找到了许多其他答案,但我无法修复它。 Most tell to check for QObject inheritance and Q_OBJECT macro.大多数告诉检查 QObject 继承和 Q_OBJECT 宏。
Have you tried sending a MainWindow*
to the ctor instead?您是否尝试过将MainWindow*
发送到 ctor? I think it is failing to map the sender function to its object:我认为它无法将发送者函数映射到它的对象:
GraphScene::GraphScene(MainWindow *parent)
: QGraphicsScene (parent), mode(NAV)
{
QObject::connect(parent, &MainWindow::changedMode, this, &GraphScene::setMode);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.