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. Connect slider and line edit??
Forum Updated to NodeBB v4.3 + New Features

Connect slider and line edit??

Scheduled Pinned Locked Moved Unsolved General and Desktop
connectqsliderqlineeditshared value
11 Posts 3 Posters 8.8k Views 2 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
    SGaist
    Lifetime Qt Champion
    wrote on 23 Jan 2017, 14:57 last edited by
    #2

    Hi,

    You can use lambdas. Or you could also use QSpinBox rather than QLineEdit and thus you could connect the two directly.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • V Offline
      V Offline
      VRonin
      wrote on 23 Jan 2017, 15:26 last edited by
      #3

      If you can use Qt5 and C++11

      connect(ui->lightOff_R_LE, &QLineEdit::textChanged, [this](const QString& val)->void{ui->lightOff_R_S->setValue(val.toInt());});
      	connect(ui->lightOff_R_S, &QSlider::valueChanged,[this](const int& val)->void{ui->lightOff_R_LE->setText(locale().toString(val));});
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • Q Offline
        Q Offline
        QT-static-prgm
        wrote on 24 Jan 2017, 15:12 last edited by
        #4

        @VRonin do you know how do bypass this error message?

        connect(ui->ambCoef, &QSpinBox::valueChanged, [this](const double& value) {emit updateAmbCoef(value); });
        

        it says it is not clear what instance of the overloaded function valueChanged should be used

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 24 Jan 2017, 15:16 last edited by VRonin
          #5

          connect(ui->ambCoef, qOverload<double>(&QDoubleSpinBox::valueChanged), [this](const double& value) {emit updateAmbCoef(value); });

          or if you are using qt<5.7

          connect(ui->ambCoef, ststic_cast<void (&QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [this](const double& value) {emit updateAmbCoef(value); });

          References:
          https://wiki.qt.io/New_Signal_Slot_Syntax

          http://doc.qt.io/qt-5/qtglobal.html#qOverload

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            QT-static-prgm
            wrote on 24 Jan 2017, 15:37 last edited by QT-static-prgm
            #6

            @VRonin both do not work

            just see you had a typo.
            static_cast<void (QDoubleSpinBox::*)(double)>
            instead of
            static_cast<void (&QDoubleSpinBox::*)(double)>

            1 Reply Last reply
            1
            • V Offline
              V Offline
              VRonin
              wrote on 24 Jan 2017, 15:40 last edited by
              #7

              what is ui->ambCoef ? it's unclear here if it's a QDoubleSpinBox or a QSpinBox

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                QT-static-prgm
                wrote on 24 Jan 2017, 15:41 last edited by
                #8

                doublespinbox. I found the problem. see my edit above

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 24 Jan 2017, 19:15 last edited by
                  #9

                  Out of curiosity, why use a lambda in that case and not signal forwarding ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • Q Offline
                    Q Offline
                    QT-static-prgm
                    wrote on 24 Jan 2017, 22:45 last edited by
                    #10

                    Because it does not work. I get qstring and need into and the other way around.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 25 Jan 2017, 08:33 last edited by
                      #11

                      But why use QLineEdit if you are only manipulating numbers ? That makes the code uselessly complicated.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      3

                      11/11

                      25 Jan 2017, 08:33

                      • Login

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