C++ Qt 27 - QTimer

VoidRealms · 108K views · 2011 · 8:21

Open on YouTube

C, C++, Rust, Go & systems languagesSoftware (other)tutorial

Why Stack Overflow recommends it

Stack Overflow users link it as a basic QTimer walkthrough when answering or asking about timer signals, slots, and Q_OBJECT-related build errors.

Recommended by 0 people across 0 different months, 2012 to 2013.

What it is

A short beginner tutorial from VoidRealms' C++ Qt series on using QTimer. It shows how to create a timer, connect its timeout() signal to a slot, and why a class needs the Q_OBJECT macro to define its own slots.

What people said

Cites SaKabmar_Ashna · 2012-09 · Stack Overflow · on “Scheduling a thread with QTtimer?”

You just need to use Qtimer to emit a signal every second.Then connect a slot to that signal where you can kick start a thread but you have to manage shared resources("my buffer") across thread. QTimer timer=new QTimer(); connect(timer,SIGNAL(timeout()),this,SLOT(On_Timeout)); timer->start(1000); Where On_Timeout is executed every second. Here are some basic tutorial on Qtimer. [this video]

Cites nairware · 2012-11 · Stack Overflow · on “Qt "No Such Slot QObject" Warning”

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 [this video] 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 {

Cites Max · 2013-01 · Stack Overflow · on “undefined reference to `vtable for myClass'”

Thanks for the explanation about macros. Now, what I did was to follow this video: [this video] But instead of breaking into class with seperated header and source, I combine all in one file. Anyway, I've tried running moc (qmake -project) and rebuilt the project again, now I have hundreds of errors more.