Qt-没有匹配函数可调用以进行连接

时间:2019-01-27 00:04:17

标签: c++ qt

尝试致电connect时出现此错误。

  

E:\ GraphTool \ graphscene.cpp:7:错误:没有匹配的函数可调用'GraphScene :: connect(QObject *&,, void(MainWindow :: )(Mode),GraphScene ,void(GraphScene :: *)(Mode))'        QObject :: connect(父级&MainWindow :: changedMode,this,&GraphScene :: setMode);

我在graphscene.cpp中称为connect

    GraphScene::GraphScene(QObject *parent) : QGraphicsScene (parent), mode(NAV) {
        QObject::connect(parent, &MainWindow::changedMode, this, &GraphScene::setMode);
    }

GraphScene类:

class GraphScene : public QGraphicsScene {
    Q_OBJECT
public:
    GraphScene(QObject *);
    void mousePressEvent(QGraphicsSceneMouseEvent*);

public slots:
    void setMode(Mode m);

private:
    Mode mode;
}

MainWindow类:

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;
};

我在这里发出信号,我不知道这是否与信号有关:

 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);
    }
}

我找到了许多其他与SO相关的答案,但无法解决。大多数告诉检查QObject继承和Q_OBJECT宏。

1 个答案:

答案 0 :(得分:1)

您是否尝试过将MainWindow*发送到ctor?我认为它无法将sender函数映射到其对象: GraphScene::GraphScene(MainWindow *parent) : QGraphicsScene (parent), mode(NAV) { QObject::connect(parent, &MainWindow::changedMode, this, &GraphScene::setMode); }