How to make a stopwatch in C++/Qt
-
Hello everyone,
I'm new to this forum and Qt and C++ in general. So I don't have much programming experience.
I'm trying to make a little Qt application (on Linux, for Linux, Fedora specifically) that can record times.
And save them in XML files. Each person will have a separate XML file for his times. Also I want to build in
an option to read the XML files and view the times of the person later on. Well I think the first step is making
a simple stopwatch application. Does anyone know how to? I have already read articles about QTimer and Ctime.
But I just don't understand them.Also it would be nice if someone could tell me which XML library (for reading and writing) is the best for a real beginner. I already been searching with Google. But I just couldn't choose. There are so many libraries. Library must be open source.
Everyone tells me to use a different one. Which is the best? It doesn't have to be really fast as I will only be reading little XML files.Kind Regards,
Superpelican
-
-
Thanks p-himik. I do understand signal and slots, I think. A signal is given when an particulary event occurs, for example when a button is pressed and a slot is a piece of code that will be executed when that signal which it' s connected to is given/fired. Is that true?
Well I don't think I understand Object Oriented Programming. And would you like to tell me what' s the name of that Qt/XML module, please?
Kind Regards,
Superpelican
EDIT: In the meantime I have found this http://bytes.com/topic/c/answers/718180-stopwatch-program and with that information I have written
this code:[code]
#include <time.h>
#include <stdio.h>int totalTime=0;
int main {
time_t start,end;if(std::cin >> "start") {
time(&start);
}
if(std::cin >> "stop") {
time(&end);
}
totalTime = end-start;
std::cout << totalTime
}
[/code]But I GCC gave these errors:
[compiler output]
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:6:5: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:7:8: error: expected primary-expression before ‘start’
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:7:8: error: expected ‘}’ before ‘start’
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:7:8: error: expected ‘,’ or ‘;’ before ‘start’
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:9:1: error: expected unqualified-id before ‘if’
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:12:1: error: expected unqualified-id before ‘if’
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:15:1: error: ‘totalTime’ does not name a type
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:16:1: error: ‘cout’ in namespace ‘std’ does not name a type
/home/Superpelican/Documents/Programming_Projects/stopwatch.cpp:17:1: error: expected declaration before ‘}’ token
[/compiler output] -
Thanks, I'm going to buy a good C++ book for beginners.
-
Consider these also :) http://developer.qt.nokia.com/books