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. Qt simple count down
Forum Updated to NodeBB v4.3 + New Features

Qt simple count down

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 168 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.
  • R Offline
    R Offline
    Ruben12313
    wrote on last edited by
    #1

    Good evening

    Im developing a project for my Senior class and in my GUI at the moment im trying to create a simple countdown but I cant quite get it right. When I press start it increments the number by 1 value and stop does 1 decrement. I tried a simple for loop in the function but I get errors in my connect area.

    Here I have it in the mainwindow.cpp above my other codes for different functions

        this->connect(this->ui->pushButton_2, SIGNAL(released()), this,SLOT(button_Start_click()));
        this->connect(this->ui->pushButton_8, SIGNAL(released()), this,SLOT(button_Stop_click()));
        this->counter=10;
        this->ui->lcdNumber->display(counter);
    

    These are the buttons

    void Race::button_Start_click()
    {
        counter--;
        this->ui->lcdNumber->display(counter);
    }
    void Race::button_Stop_click()
    {
    
      terminate();
        break;
        this->ui->lcdNumber->display(counter);
    }
    
    Pl45m4P 1 Reply Last reply
    0
    • R Ruben12313

      Good evening

      Im developing a project for my Senior class and in my GUI at the moment im trying to create a simple countdown but I cant quite get it right. When I press start it increments the number by 1 value and stop does 1 decrement. I tried a simple for loop in the function but I get errors in my connect area.

      Here I have it in the mainwindow.cpp above my other codes for different functions

          this->connect(this->ui->pushButton_2, SIGNAL(released()), this,SLOT(button_Start_click()));
          this->connect(this->ui->pushButton_8, SIGNAL(released()), this,SLOT(button_Stop_click()));
          this->counter=10;
          this->ui->lcdNumber->display(counter);
      

      These are the buttons

      void Race::button_Start_click()
      {
          counter--;
          this->ui->lcdNumber->display(counter);
      }
      void Race::button_Stop_click()
      {
      
        terminate();
          break;
          this->ui->lcdNumber->display(counter);
      }
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Ruben12313

      Hi,

      first, you don't need to write this-> in front of every expression.
      Like

      // here
      this->connect
      
      // here
      this->counter=10;
      
      // or here
      this->ui->lcdNumber->display(counter);
      

      Without this everywhere the code looks a little cleaner.
      You only need this when addressing "this" instance, like in the connect statement, where you want to connect to the current class and object.
      And when dealing with two identical variables... one local, the other a member of "this" class (in a setter function, for example)
      Then it's:

      void setCounter(int counter)
      {
          this->counter = counter;
      }
      

      Left-hand side your member, right-hand side the local variable that you pass in.
      Without the this there, they have to have different names, or it won't work.

      break;
      

      What should the break; do there?
      What is terminate() doing?

      You said start_click() should increment the counter, but in there you are doing

      counter--;
      

      ?

      And for what are you planning to use a loop?
      If you want to continuously increase or decrease the counter without clicking, you need a timer (QTimer)
      Please explain what exactly you are trying to achieve.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2

      • Login

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