0

I'm trying to connect a signal and a slot. I had it working, but I accidentally deleted a .h file. Now I tried to rewrite it, and everything's gone to hell. I've got:

#ifndef GAMEMANAGER_H
#define GAMEMANAGER_H

#include "gamepersistence.h"

class GameManager
{
    Q_OBJECT
public:
    GameManager();
    ~GameManager();

    GamePersistence* _gamePersistece;
// other stuff
 signals:
    void refreshPlease();
    void gameOverSignal();
};

#endif // GAMEMANAGER_H

And then I'm trying to connect it in another class:

GameWindow::GameWindow(QWidget *parent)
    : QWidget(parent)
{
    setFixedSize(900,200);
    setWindowTitle(trUtf8("Amőba"));

    //this->setStyleSheet("background-color: white;");
    _gameManager = new GameManager();
//    _gameManager->setFocusPolicy(Qt::StrongFocus);
    connect(_gameManager, SIGNAL(gameOverSignal()), this, SLOT(gameOver()));
    connect(_gameManager, SIGNAL(refreshPlease()), this, SLOT(refreshTable()));
//other stuff
}

This is in a class called GameWindow. Now I'm getting errors for the two connect lines:

error: no matching function for call to 'GameWindow::connect(GameManager*&, const char*, GameWindow* const, const char*)' connect(_gameManager, SIGNAL(gameOverSignal()), this, SLOT(gameOver()));

What did I mess up in the header? I think I've rewritten it as it was...

lte__
  • 7,175
  • 25
  • 74
  • 131

2 Answers2

1

Figured it out, I have to use the : public QObject base class.

lte__
  • 7,175
  • 25
  • 74
  • 131
-1

in gamemanager.h add the public inheritance from QObject for signal and slot can be called.

class GameManager : public QObject{ //your class definition };