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
QtWS25 Last Chance

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.
  • ronyNSR Offline
    ronyNSR Offline
    ronyNS
    wrote on last edited by ronyNS
    #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
    • Camilo del RealC Offline
      Camilo del RealC Offline
      Camilo del Real
      wrote on 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");
      }
      
      
      ronyNSR 1 Reply Last reply
      2
      • Camilo del RealC Camilo del Real

        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");
        }
        
        
        ronyNSR Offline
        ronyNSR Offline
        ronyNS
        wrote on last edited by
        #3

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

        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