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. Catching the value of a spinbox

Catching the value of a spinbox

Scheduled Pinned Locked Moved Solved General and Desktop
spinboxc++qt 5.7designercode
3 Posts 2 Posters 1.6k Views
  • 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
    ronyNS
    wrote on 7 Sept 2016, 15:12 last edited by ronyNS 9 Jul 2016, 15:44
    #1
    if (ui->spinBox->value()==20){
    
            ui->label_2->setText("low stock");
        }
    

    Im trying to change the text of a label when the value of spinbox is 20.
    However this code does not do anything.
    i tried storing the value in a variable and that also does not work .
    Please help.
    Thank you.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Camilo del Real
      wrote on 7 Sept 2016, 17:52 last edited by
      #2

      You must capture valueChanged(int) signal from the spinner:

      //.h
      private slots:
      ...
          void captureValue(int v);
      ...
      
      //.cpp
      //Constructor
      <NombreClase>(){
          ...
          connect(ui->spinbox, SIGNAL(valueChanged(int)), this, SLOT(captureValue(int)));
      }
      
      void <NombreClase>::captureValue(int v)
      {
          if(v < 20) ui->label_2->setText("low stock");
          else if(v >= 20 && v <= 300) ui->label_2->setText("normal stock");
          else ui->label_2->setText("high stock");
      }
      
      
      R 1 Reply Last reply 8 Sept 2016, 06:40
      2
      • C Camilo del Real
        7 Sept 2016, 17:52

        You must capture valueChanged(int) signal from the spinner:

        //.h
        private slots:
        ...
            void captureValue(int v);
        ...
        
        //.cpp
        //Constructor
        <NombreClase>(){
            ...
            connect(ui->spinbox, SIGNAL(valueChanged(int)), this, SLOT(captureValue(int)));
        }
        
        void <NombreClase>::captureValue(int v)
        {
            if(v < 20) ui->label_2->setText("low stock");
            else if(v >= 20 && v <= 300) ui->label_2->setText("normal stock");
            else ui->label_2->setText("high stock");
        }
        
        
        R Offline
        R Offline
        ronyNS
        wrote on 8 Sept 2016, 06:40 last edited by
        #3

        @Camilo-del-Real
        That worked.
        Thanks :)

        1 Reply Last reply
        0

        3/3

        8 Sept 2016, 06:40

        • Login

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