So I am writing a program that displays each letter of a word for 1 second with a 1 second interval between the letters. (It\'s for a spelling exercise for grade 1). I am curren
This is happening, because you're blocking the thread. In most cases you're interested in using event loop.
You can use timer and increment a counter in a slot function. Every QObject
has support for timer. You can start it using int QObject::startTimer(int interval)
and it will call virtual void timerEvent(QTimerEvent *event)
every interval
miliseconds (it's a virtual method - reimplement it).
You can also use QTimer
and connect QTimer::timeout()
signal to accomplish the same thing.
Inside timer handler increment a counter and print the character.
It's a good idea to put your hands on finite state machine concept. FSMs are a great tool for solving similar problems problems. In fact, using a timer callback you create a state machine, but very simple one.