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.
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