Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:39:01+00:00 2026-06-14T11:39:01+00:00

I am trying to connect a signal and slot using a QTimer as the

  • 0

I am trying to connect a signal and slot using a QTimer as the sender of a signal. Unfortunately, when I compile the code below, the program runs, but I receive a warning: “no such slot QObject::flip() in game.cpp”.

It seems that my slot is not properly defined. Using a Youtube tutorial about QTimer, it sounded as though I needed to add the “Q_OBJECT” macro inside the game class (this is commented out below). However, if I uncomment it, the program fails to compile, providing the error message: “undefined reference to ‘vtable for Game'”.

How do I properly connect my signal and slot for the timer?

game.h

#ifndef GAME_H
#define GAME_H

#include "player.h"
#include <QtCore>

class Game : public QObject {

    //Q_OBJECT

public:
    Game();
    void timed_job();

public slots:
    void flip();

private:
    bool is_game_on;
    QTimer *timer;

    Player player_1;
    Player player_2;
    Player player_3;
};

#endif // GAME_H

game.cpp

#include "game.h"
#include <QtCore>

Game::Game() {
    is_game_on = true;
}

void Game::timed_job() {
    timer = new QTimer(this);
    timer->start(1000);
    connect(timer, SIGNAL(timeout()), this, SLOT(flip()));
}

void Game::flip() {
    if(is_game_on == true) {
        is_game_on = false;
    }
    else {
        is_game_on = true;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:39:02+00:00Added an answer on June 14, 2026 at 11:39 am

    You need Q_OBJECT macro for the slot to be recognized.

    The compile time error is caused by missing MOC generated units. Uncomment the line and delete the Makefile generated to force qmake to regenerate the necessary links.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect to a FTP using Apaches FTPSClient but I keep getting
I am trying to connect to BlueDevil::Manager::devicesChanged , but when I run my program
Im trying to connect a Information object to many Customers (see code below) When
I have MainWindow and QNAMRedirect classes and I am trying to compile program but
I'm trying to move a sprite in a QGraphicsView. I use : connect(timer, SIGNAL(timeout()),
I am trying to connect to a MySQL Server using JDBC tool in java
I'm trying to connect a signal from a QProcess inside my mainwindow() object to
I'm trying to write an application using QNetworkManager. I have simplified the code down
I am trying to connect to a signal in this way: QObject::connect(myObj, SIGNAL(mySignal(std::list<MyClass*> myList)),
I am trying to connect two widgets through the signals/slots option but I keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.