Im currently coding a very basic c++ timer app witch is supposed to output the elapsed time since the start button was clicked.
Im using a label and two buttons(start and stop) from the Gtkmm libraries.
The problem is that the app freezes up during the time my wait function is running. This might seem pretty obvious but i had hoped to be able to stop the timer any time. Once the wait function is finished everything works fine again.
Is there a better way to get the output once every second and still be able to perform other actions during that time?
Im using the Gtkmm libraries to do the graphical stuff, i dont know if the problem could be connected to that somehow.
Anyway. These are the important parts of my code:
CODE
void myWindow::wait (int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC;
while (clock() < endwait) {}
}
void myWindow::on_start_clicked()
{
go = true;
start = time(NULL);
while(go == true)
{
end = time(NULL);
secs = difftime(end,start);
std::cout <<"Elapsed time: "<< secs << "\n";
myWindow::wait(1);
}
}
void myWindow::on_stop_clicked()
{
go = false;
}
Thanks for your time.