I'm trying to run a function for about 5 seconds using the QTimer
function. After studying the documentation and testing, I can't seem to find a function that does this in Qt.
I've tried the following approaches:
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(myFunction());
timer->start(5000);
This approach runs the function after every 5 seconds. This is not what I'm trying to achieve. I also attempted to use the singleShot()
property using the following code:
QTimer::singleShot(5000,this,SLOT(myFunction()));
This function simply fires my function once. Is there any property of QTimer
that can run my function for a given time. Something like:
run function and timeout function after 5 seconds.
EDIT: More Info:
This is for a robot competition in my University. What I'm driving to do is drive the wheels of a robot over TCP. I know how many seconds both wheels need to run to get the robot to turn a certain angle. The SLOT in myFunction
will be something like senddatatoRobot()
The function basically sends data over TCP to my robot, turning it a certain angle based on the orientation of the robot from a desired endpoint. For example, I know my robot will make a 360 degree turn if I send a PWM value of 4096 and 0 to the left and right wheels for 5 seconds. So to make a 45 degree turn for example, I would send data for a specified number of seconds.