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. Signal/Slots doesn't work with QSlider and QDoubleSpinBox

Signal/Slots doesn't work with QSlider and QDoubleSpinBox

Scheduled Pinned Locked Moved Solved General and Desktop
signals&slotsqsliderqdoublespinbox
24 Posts 5 Posters 10.8k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 16 May 2016, 16:51 last edited by
    #1

    Hi,
    this line Code doesn't work:

     connect(sliderHeight, SIGNAL(valueChanged(int)), m_hightSpinBox, SLOT(setValue(double)) );
    

    I have this Code in a header-file in a class

    class ResizeImageDialog : public QDialog
    {
    Q_OBJECT
    
    double         m_ratio;
    
    QLabel         *m_widthLabel;
    QLabel         *m_hightLabel;
    QDoubleSpinBox *m_widthSpinBox;
    QDoubleSpinBox *m_hightSpinBox;
    QCheckBox      *m_keepRatioCheckBox;
    QPushButton    *m_okButton;
    QPushButton    *m_cancelButton;
    QSlider        *sliderWidth;
    QSlider        *sliderHeight;
    QHBoxLayout    *m_widthLayout;
    QHBoxLayout    *m_hightLayout;
    QHBoxLayout    *m_buttonLayout;
    QVBoxLayout    *m_generalLayout;
    
    
    public:
    ResizeImageDialog(QWidget * parent = 0, double imageWidth = 100.0, double imageHight = 100.0) : QDialog(parent)
    {
       m_widthLabel = new QLabel("Breite");
       m_hightLabel = new QLabel("Höhe");
    
       m_widthSpinBox = new QDoubleSpinBox;
       m_widthSpinBox->setMaximum(1500);
       m_widthSpinBox->setValue(imageWidth);
    
       sliderHeight = new QSlider(Qt::Horizontal);
       sliderHeight->setMaximum(1500);
       sliderHeight->setMinimum(0);
       sliderWidth  = new QSlider(Qt::Horizontal);
       sliderWidth->setMaximum(1500);
       sliderWidth->setMinimum(0);
    
    
       m_hightSpinBox = new QDoubleSpinBox;
       m_hightSpinBox->setMaximum(1500);
       m_hightSpinBox->setValue(imageHight);
       connect(m_hightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(hightChanged(double)));
       connect(sliderHeight, SIGNAL(valueChanged(int)), m_hightSpinBox, SLOT(setValue(double)) );
    
       m_ratio = imageWidth / imageHight;
    
       m_keepRatioCheckBox = new QCheckBox("Keep ratio",this);
       m_keepRatioCheckBox->setChecked(true);
    
    
       m_widthLayout = new QHBoxLayout;
       m_widthLayout->addWidget(m_widthLabel);
       m_widthLayout->addWidget(m_widthSpinBox);
       m_widthLayout->addWidget(sliderWidth);
    
       m_hightLayout = new QHBoxLayout;
       m_hightLayout->addWidget(m_hightLabel);
       m_hightLayout->addWidget(m_hightSpinBox);
       m_hightLayout->addWidget(sliderHeight);
    
       m_okButton = new QPushButton("Ok");
       connect(m_okButton, SIGNAL(clicked()), this, SLOT(accept()));
    
    
       m_cancelButton = new QPushButton("Abbrechen");
       connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    
       m_buttonLayout = new QHBoxLayout;
       m_buttonLayout->addStretch();
       m_buttonLayout->addWidget(m_okButton);
       m_buttonLayout->addWidget(m_cancelButton);
    
       m_generalLayout = new QVBoxLayout;
       m_generalLayout->addLayout(m_widthLayout);
       m_generalLayout->addLayout(m_hightLayout);
       m_generalLayout->addWidget(m_keepRatioCheckBox);
       m_generalLayout->addLayout(m_buttonLayout);
       setLayout(m_generalLayout);
    
       setMaximumSize(300, 300);
       setModal(true);
       //resize(670,630);
       setWindowTitle(tr("Bildgröße ändern"));
       setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    }
    
    static QPair<double, double> getNewSize(QWidget * parent = 0, double imageWidth = 100.0, double imageHight = 100.0)
    {
       ResizeImageDialog dlg(parent, imageWidth, imageHight);
    
       dlg.exec();
    
    
    
       QPair<double, double> size;
       size.first  = dlg.m_widthSpinBox->value();
       size.second = dlg.m_hightSpinBox->value();
       return size;
    }
    };
    

    Why doesn't work that?

    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 16 May 2016, 16:57 last edited by
      #2

      @HenrikSt. said:
      hi
      does connect(sliderHeight,xxx
      return true
      is the slot setValue called?

      U must define better "doesn't work" :)

      ? 1 Reply Last reply 16 May 2016, 17:04
      0
      • M mrjj
        16 May 2016, 16:57

        @HenrikSt. said:
        hi
        does connect(sliderHeight,xxx
        return true
        is the slot setValue called?

        U must define better "doesn't work" :)

        ? Offline
        ? Offline
        A Former User
        wrote on 16 May 2016, 17:04 last edited by
        #3

        @mrjj
        QObject::connect: No such slot ResizeImageDialog::hightChanged(double) in ..\TextPad\PagesTextEdit.h:167
        QObject::connect: Incompatible sender/receiver arguments
        QSlider::valueChanged(int) --> QDoubleSpinBox::setValue(double)
        yes: false

        M 1 Reply Last reply 16 May 2016, 17:05
        0
        • ? A Former User
          16 May 2016, 17:04

          @mrjj
          QObject::connect: No such slot ResizeImageDialog::hightChanged(double) in ..\TextPad\PagesTextEdit.h:167
          QObject::connect: Incompatible sender/receiver arguments
          QSlider::valueChanged(int) --> QDoubleSpinBox::setValue(double)
          yes: false

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 16 May 2016, 17:05 last edited by
          #4

          @HenrikSt.
          So what ever you are trying to connect, its not correct.

          " Incompatible sender/receiver arguments"

          I think it means
          valueChanged(int) <<< INT to setValue(double)) << double

          change setValue to int

          ? 1 Reply Last reply 16 May 2016, 17:07
          1
          • M mrjj
            16 May 2016, 17:05

            @HenrikSt.
            So what ever you are trying to connect, its not correct.

            " Incompatible sender/receiver arguments"

            I think it means
            valueChanged(int) <<< INT to setValue(double)) << double

            change setValue to int

            ? Offline
            ? Offline
            A Former User
            wrote on 16 May 2016, 17:07 last edited by
            #5

            @mrjj
            QObject::connect: No such slot ResizeImageDialog::hightChanged(double) in ..\TextPad\PagesTextEdit.h:167
            QObject::connect: No such slot QDoubleSpinBox::setValue(int) in ..\TextPad\PagesTextEdit.h:168
            yes: false

            M 1 Reply Last reply 16 May 2016, 17:08
            0
            • ? A Former User
              16 May 2016, 17:07

              @mrjj
              QObject::connect: No such slot ResizeImageDialog::hightChanged(double) in ..\TextPad\PagesTextEdit.h:167
              QObject::connect: No such slot QDoubleSpinBox::setValue(int) in ..\TextPad\PagesTextEdit.h:168
              yes: false

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 16 May 2016, 17:08 last edited by
              #6

              @HenrikSt.
              Says it cant see the slot function
              ResizeImageDialog::hightChanged

              check spelling etc.

              ? 1 Reply Last reply 16 May 2016, 17:10
              0
              • M mrjj
                16 May 2016, 17:08

                @HenrikSt.
                Says it cant see the slot function
                ResizeImageDialog::hightChanged

                check spelling etc.

                ? Offline
                ? Offline
                A Former User
                wrote on 16 May 2016, 17:10 last edited by
                #7

                @mrjj
                hightChanged is not important.

                The Code under that -> QDoubleSpinBox::setValue(int)

                M 1 Reply Last reply 16 May 2016, 17:15
                0
                • ? A Former User
                  16 May 2016, 17:10

                  @mrjj
                  hightChanged is not important.

                  The Code under that -> QDoubleSpinBox::setValue(int)

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 16 May 2016, 17:15 last edited by
                  #8

                  @HenrikSt.
                  well check spelling and parameters.

                  ? 2 Replies Last reply 16 May 2016, 18:36
                  0
                  • M mrjj
                    16 May 2016, 17:15

                    @HenrikSt.
                    well check spelling and parameters.

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on 16 May 2016, 18:36 last edited by
                    #9

                    @mrjj
                    From valueChanged and setValue?

                    1 Reply Last reply
                    0
                    • M mrjj
                      16 May 2016, 17:15

                      @HenrikSt.
                      well check spelling and parameters.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on 16 May 2016, 18:47 last edited by
                      #10

                      @mrjj
                      But the spelling is correct...

                      Should i paste the all files in Project or a link to them?

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 16 May 2016, 19:50 last edited by
                        #11

                        which objects are you trying to bind ?
                        show your connect statement after the change to int.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 16 May 2016, 21:41 last edited by
                          #12

                          Hi,

                          QDoubleSpinBox has no such slot, only setValue(double). Use the new Qt 5 notation for your connection, that will solve your problem.

                          i.e.

                          connect(sliderHeight, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
                          

                          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 17 May 2016, 08:48
                          2
                          • J Offline
                            J Offline
                            JKSH
                            Moderators
                            wrote on 17 May 2016, 05:12 last edited by
                            #13

                            See http://doc.qt.io/qt-5/signalsandslots-syntaxes.html#type-checking-and-implicit-type-conversions -- it uses exactly QSlider and QDoubleSpinBox in an example, and explains why it "doesn't work" with the old connection style.

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            3
                            • S SGaist
                              16 May 2016, 21:41

                              Hi,

                              QDoubleSpinBox has no such slot, only setValue(double). Use the new Qt 5 notation for your connection, that will solve your problem.

                              i.e.

                              connect(sliderHeight, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
                              
                              ? Offline
                              ? Offline
                              A Former User
                              wrote on 17 May 2016, 08:48 last edited by
                              #14

                              @SGaist
                              Thank you, it works!

                              But how can do that:

                              I have a chackbox. If the Checkbox is checked, the two spinboxes are Ratio. If i changed one slider, the other slider changed too. They both are Ratio to each other.

                              Do you understand?

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 17 May 2016, 10:13 last edited by
                                #15

                                Not really. Should both QDoubleSpinbox have the same value if that checkbox is checked?

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                ? 1 Reply Last reply 17 May 2016, 11:44
                                0
                                • J jsulm
                                  17 May 2016, 10:13

                                  Not really. Should both QDoubleSpinbox have the same value if that checkbox is checked?

                                  ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on 17 May 2016, 11:44 last edited by
                                  #16

                                  @jsulm
                                  They should have the value when:

                                  1. The Checkbox is checked and
                                  2. one slider is dragged. So than both checkboxes have the value from slider

                                  U understand?

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 17 May 2016, 11:53 last edited by
                                    #17

                                    Unfortunately not:
                                    First version: "I have a chackbox. If the Checkbox is checked, the two spinboxes are Ratio. If i changed one slider, the other slider changed too. They both are Ratio to each other."

                                    Second version: "
                                    The Checkbox is checked and
                                    one slider is dragged. So than both checkboxes have the value from slider"

                                    In the first version you are talking about two spinboxes in the second version you are talking about two checkboxes. Sorry, but I'm lost...
                                    And you did not answer my question whether both spinboxes (I assume you really mean spinboxes) should have the same value if one of them is changed while checkbox is checked.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    ? 1 Reply Last reply 17 May 2016, 11:55
                                    0
                                    • J jsulm
                                      17 May 2016, 11:53

                                      Unfortunately not:
                                      First version: "I have a chackbox. If the Checkbox is checked, the two spinboxes are Ratio. If i changed one slider, the other slider changed too. They both are Ratio to each other."

                                      Second version: "
                                      The Checkbox is checked and
                                      one slider is dragged. So than both checkboxes have the value from slider"

                                      In the first version you are talking about two spinboxes in the second version you are talking about two checkboxes. Sorry, but I'm lost...
                                      And you did not answer my question whether both spinboxes (I assume you really mean spinboxes) should have the same value if one of them is changed while checkbox is checked.

                                      ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on 17 May 2016, 11:55 last edited by
                                      #18

                                      @jsulm
                                      Yes, sorry. I mean SpinBoxes...

                                      Your Question:

                                      Yes, both should have the same value when the ceckbox is checked:

                                         if (m_keepRatioCheckBox->isChecked())
                                         {
                                            connect(sliderHeight, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
                                            connect(sliderHeight, &QSlider::valueChanged, m_widthSpinBox, &QDoubleSpinBox::setValue);
                                            connect(sliderWidth, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
                                            connect(sliderWidth, &QSlider::valueChanged, m_widthSpinBox, &QDoubleSpinBox::setValue);
                                         }
                                      

                                      This won't work..

                                      1 Reply Last reply
                                      0
                                      • J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 17 May 2016, 12:01 last edited by
                                        #19

                                        What you could do: if, for example, sliderHeight is changed you do not set m_widthSpinBox directly, but instead you calculate the difference between m_hightSpinBox and its new value and add this difference (which can be negative) to m_widthSpinBox.
                                        You will need your own slots for that.

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        ? 1 Reply Last reply 17 May 2016, 12:02
                                        0
                                        • J jsulm
                                          17 May 2016, 12:01

                                          What you could do: if, for example, sliderHeight is changed you do not set m_widthSpinBox directly, but instead you calculate the difference between m_hightSpinBox and its new value and add this difference (which can be negative) to m_widthSpinBox.
                                          You will need your own slots for that.

                                          ? Offline
                                          ? Offline
                                          A Former User
                                          wrote on 17 May 2016, 12:02 last edited by
                                          #20

                                          @jsulm
                                          Can you make/Show an example, please?

                                          1 Reply Last reply
                                          0

                                          7/24

                                          16 May 2016, 17:10

                                          topic:navigator.unread, 17
                                          • Login

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