Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make a stopwatch in C++/Qt

How to make a stopwatch in C++/Qt

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Superpelican
    wrote on last edited by
    #1

    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

    www.superpelican.tk

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

      If you don't understand article about QTimer you really should read more about Qt and/or C++ (do you understand signals and slots, basics of OOP?).

      There is a module in Qt for Xml so it's unlikely that you will need some other library for your project.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Superpelican
        wrote on last edited by
        #3

        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]

        www.superpelican.tk

        1 Reply Last reply
        0
        • P Offline
          P Offline
          p-himik
          wrote on last edited by
          #4

          Superpelican, you really have to read some books about C++ because your code shows significant lack of knowledge in C++ (and C).

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Superpelican
            wrote on last edited by
            #5

            Thanks, I'm going to buy a good C++ book for beginners.

            www.superpelican.tk

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rahul Das
              wrote on last edited by
              #6

              Consider these also :) http://developer.qt.nokia.com/books


              Declaration of (Platform) independence.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved