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. Change value of a QDoubleSpinBox
Forum Updated to NodeBB v4.3 + New Features

Change value of a QDoubleSpinBox

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • K Offline
    K Offline
    KevKr
    wrote on last edited by
    #1

    Hello everybody !

    I'm currently working on an application which works with a serial port. I've designed a interface (UI) with a QDoubleSpinBox. When I get a data from the serial port, I need to change the value of a QDoubleSpinBox directly in my program with a variable. Example :

    double myVar = 1.2; // 1.2 is just an example
    ui->mySpinBox->setValue(myVar); // QDoubleSpinBox (UI)

    This code is not working. The minimum value of the spinbox is set. "setValue" need a double variable in parameter. What is the correct way to change the value of my spinbox ? If it's not possible, has someone another way to do ?

    I use QtCreator 3.5.1 and Qt 5.5.1.

    KevKr

    kshegunovK 1 Reply Last reply
    0
    • K KevKr

      Hello everybody !

      I'm currently working on an application which works with a serial port. I've designed a interface (UI) with a QDoubleSpinBox. When I get a data from the serial port, I need to change the value of a QDoubleSpinBox directly in my program with a variable. Example :

      double myVar = 1.2; // 1.2 is just an example
      ui->mySpinBox->setValue(myVar); // QDoubleSpinBox (UI)

      This code is not working. The minimum value of the spinbox is set. "setValue" need a double variable in parameter. What is the correct way to change the value of my spinbox ? If it's not possible, has someone another way to do ?

      I use QtCreator 3.5.1 and Qt 5.5.1.

      KevKr

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @KevKr said in Change value of a QDoubleSpinBox:

      This code is not working.

      What is not working exactly?

      @KevKr said in Change value of a QDoubleSpinBox:

      What is the correct way to change the value of my spinbox ?

      This is the correct way.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KevKr
        wrote on last edited by
        #3

        When my serial port is changing the value of "myVar", this value is not correctly printed in my spinbox. When I insert a qDebug(), I can see the value of myVar (1.2 in my example), but in the spinbox, the value is always -100 (the minimum value I've configured).

        kshegunovK 1 Reply Last reply
        0
        • K KevKr

          When my serial port is changing the value of "myVar", this value is not correctly printed in my spinbox. When I insert a qDebug(), I can see the value of myVar (1.2 in my example), but in the spinbox, the value is always -100 (the minimum value I've configured).

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @KevKr
          Yes, everything works as designed. Look up "Arguments passed by value and by reference" in this article for an explanation of why it doesn't work as you expect.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • K Offline
            K Offline
            KevKr
            wrote on last edited by
            #5

            Thank you ! Finally I've solved my problem. It was just a mistake in my algorithm, I didn't use the right variable. I've lost a couple of hours with that. Really sorry !

            If someone want to get my code to change the value of a spinbox, this code is working.

            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