QObject::connect: No such slot
-
Hello!
I am using a connect function but it will not recognize my variable as a slot even though it is such. Here is a part of the code.gameclass.h
class GameLoop : public QGraphicsView { ... public slots: void multiply_ghosts(); };
gameclass.cpp
#include "gameclass.h" void GameLoop::ft_roll_game() { timer_multi = new QTimer(); QObject::connect(timer_multi, SIGNAL(timeout()), this, SLOT(multiply_ghosts())); timer_multi->start(3000); } void GameLoop::multiply_ghosts(){ std::cout<<"Multiplying"; }
I get this warning and the message does not show in console(which means the timer is not working):
qt.core.qobject.connect: QObject::connect: No such slot QGraphicsView::multiply_ghosts() in .. -
Switch to the new(er) connect syntax so you may get a more detailed error message at compile time instead of run time:
QObject::connect(timer_multi, &QTimer::timeout, this, &GameLoop::multiply_ghosts);
Also, you didn't show all of your GameLoop header, does it include the Q_OBJECT macro?
-
Thanks! It worked thanks to the newer syntax.