user10422449
user10422449

Reputation: 19

Adding a timer to a qt application

I'm attempting to build a program which takes any text file and turns it into a typing test. It has a timer that will display to the screen.

However, I can't figure out how to display the timer while actually running my game instructions. The timer works and displays the elapsed time but displaying the timer is the only thing it will do.

Can anyone give me some pointers of things that might be helpful for solving this problem?

Upvotes: 0

Views: 920

Answers (2)

wysiwyg
wysiwyg

Reputation: 11

QTimer emits timeout() signal in every time interval specified by you unless it's a 'single-shot' timer.

If you want to display the elapsed time, connect the timeout() signal of your timer object to your slot which will display the time elapsed. Your slot will contain your logic to display whatever you want.

Upvotes: 1

Bhoot
Bhoot

Reputation: 179

QTimer has a signal timeout() which will be emitted after your interval time is elapsed. A QTimer unless specified as a singleshot runs again and again.

Let's assume you wish to do something every second, you can start a timer with interval 1000 (in msec). You can then connect its timeout signal to a slot. There you can specify how to go about doing stuff.

It's fine to run multiple timers at the same time. Also, for your initial implementation (for displaying the timer); you might want to take a look at QElapsedTimer.

Edit:

I found this example. It might provide you something to look at.

Upvotes: 1

Related Questions