1
votes

I have this error when I tried to call 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);

I called connect in graphscene.cpp

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

The GraphScene class :

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. Most tell to check for QObject inheritance and Q_OBJECT macro.

1
Have you tried sending a MainWindow* to the ctor instead? I think it is failing to map the sender function to its object:cppGraphScene::GraphScene(MainWindow *parent) : QGraphicsScene (parent), mode(NAV) { QObject::connect(parent, &MainWindow::changedMode, this, &GraphScene::setMode); }Tupaschoal
I realised the use of signals and slots is uncalled for in my case (I can just call directly). But I'm still curious why it didn't work.Haj Ayed Amir
See my edit above, though I apologize for not writing it prettierTupaschoal
Nice, I'll post it as answers then.Tupaschoal

1 Answers

2
votes

Have you tried sending a MainWindow* to the ctor instead? 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);
}