Search code examples
c++qtgraphicsqobject

Adding signals to class that inherit from QGraphicsScene


I want to add a signal to a class that inherits from QGraphicsScene.

signals:
    void update(std::vector< std::vector<int> > board);

When I do this, Qt Creator warns me that I forgot the Q_OBJECT macro. But somewhere I read that since QGraphicsScene doesn't inherit from QObject, I shouldn't put it in my class definition. But signals need this macro.

How do I add a signal to a class that doesn't inherit from QObject?


boardgui.h

#ifndef BOARDGUI_H
#define BOARDGUI_H
#include <QGraphicsView>
#include <QGraphicsScene>

class BoardGUI : public QGraphicsScene
{
    Q_OBJECT
public:
    BoardGUI(QGraphicsView*& view, int dimension);
    ~BoardGUI();
    void buildBoard();
signals:
    void update(std::vector< std::vector<int> > board);
private:
    int dimension;
    QGraphicsView* view;
};

#endif // BOARDGUI_H

Solution

  • Reposting as answer, as requested:

    Is update() your signal? did you try to implement the signal yourself? If yes, don't do that, signals are defined by moc.