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. Qt DoubleSpin Box value changed slot has called twice
Forum Updated to NodeBB v4.3 + New Features

Qt DoubleSpin Box value changed slot has called twice

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt creatorqt 5.5c++slotsdebugger
22 Posts 6 Posters 11.9k 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 Sowmiya R

    @raven-worx
    ya, I have checked the stack traces.
    both call has same traces

    on_doublespinbox_valuechaged()
    qt_static_metacall
    qt_metacall

    Thanks,
    Sowmiya

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #4

    @Sowmiya-R
    then you probably have done the connection to the signal twice.

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sowmiya R
      wrote on last edited by
      #5

      @raven-worx

      I did't use any connect statement.
      From Qtdoublespinbox right click option , I have clicked "Go to slot " and I selected value changed(QString) signal.
      then it created slot function in CPP.

      This is how I made the connection.

      raven-worxR 1 Reply Last reply
      0
      • S Sowmiya R

        @raven-worx

        I did't use any connect statement.
        From Qtdoublespinbox right click option , I have clicked "Go to slot " and I selected value changed(QString) signal.
        then it created slot function in CPP.

        This is how I made the connection.

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #6

        @Sowmiya-R
        and no calls to QMetaObject::connectSlotsByName() for example?
        I don't know if this is called implicitly. But you can try to rename the slot.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sowmiya R
          wrote on last edited by
          #7

          @raven-worx

          Can you please elaborate your answer.

          thanks,
          Sowmiya

          raven-worxR 1 Reply Last reply
          0
          • S Sowmiya R

            @raven-worx

            Can you please elaborate your answer.

            thanks,
            Sowmiya

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #8

            @Sowmiya-R
            simply try to rename the on_doublespinbox_valuechaged() slot

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sowmiya R
              wrote on last edited by
              #9

              @raven-worx

              I have renamed the slot and connected in following way,

              connect(ui->doubleSpinBox, SIGNAL(valueChanged(QString)), this, SLOT(doubleSpinBoxvalueChanged1(QString)));

              Now also, the slot has called twice only if I click Qt doublespinbox up/down control.

              If I press keyboard up/down key or mouse scroll up/down button, the slot has called once.

              Thanks,
              Sowmiya

              raven-worxR 1 Reply Last reply
              0
              • S Sowmiya R

                @raven-worx

                I have renamed the slot and connected in following way,

                connect(ui->doubleSpinBox, SIGNAL(valueChanged(QString)), this, SLOT(doubleSpinBoxvalueChanged1(QString)));

                Now also, the slot has called twice only if I click Qt doublespinbox up/down control.

                If I press keyboard up/down key or mouse scroll up/down button, the slot has called once.

                Thanks,
                Sowmiya

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #10

                @Sowmiya-R
                there must be anything in your code causing this misbehavior.
                Did you reimplement any event-handlers, event-filters, widgets, etc. in your application?

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  Hi
                  Tried with 5.5.1 in default GUI project
                  Cannot reproduce.
                  alt text

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sowmiya R
                    wrote on last edited by
                    #12

                    I have created a sample application, it contains only QtdoubleSpinbox.
                    I have not overridden any methods.

                    below is my CPP code

                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    #include "qdebug.h"
                    #include <qspinbox.h>
                    
                    MainWindow::MainWindow(QWidget *parent) :
                        QMainWindow(parent),
                        ui(new Ui::MainWindow)
                    {
                    
                        ui->setupUi(this);
                        connect(ui->doubleSpinBox, SIGNAL(valueChanged(QString)), this, SLOT(on_doubleSpinBox_valueChanged1(QString)));
                    }
                    
                    MainWindow::~MainWindow()
                    {
                        delete ui;
                    }
                    
                    void MainWindow::on_doubleSpinBox_valueChanged1(const QString &arg1)
                    {
                        qDebug()<<"doubleSpinBox value changed: "<<arg1;
                    }
                    
                    mrjjM 1 Reply Last reply
                    0
                    • S Sowmiya R

                      I have created a sample application, it contains only QtdoubleSpinbox.
                      I have not overridden any methods.

                      below is my CPP code

                      #include "mainwindow.h"
                      #include "ui_mainwindow.h"
                      #include "qdebug.h"
                      #include <qspinbox.h>
                      
                      MainWindow::MainWindow(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::MainWindow)
                      {
                      
                          ui->setupUi(this);
                          connect(ui->doubleSpinBox, SIGNAL(valueChanged(QString)), this, SLOT(on_doubleSpinBox_valueChanged1(QString)));
                      }
                      
                      MainWindow::~MainWindow()
                      {
                          delete ui;
                      }
                      
                      void MainWindow::on_doubleSpinBox_valueChanged1(const QString &arg1)
                      {
                          qDebug()<<"doubleSpinBox value changed: "<<arg1;
                      }
                      
                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @Sowmiya-R
                      Must be something in your Qt/compiler I guess ??
                      Can you try this test
                      https://www.dropbox.com/s/9eftxqghndn2bhw/myspinbox.zip?dl=0

                      S 1 Reply Last reply
                      0
                      • Vinod KuntojiV Offline
                        Vinod KuntojiV Offline
                        Vinod Kuntoji
                        wrote on last edited by
                        #14

                        @Sowmiya-R ,
                        Hi,
                        You can use Qt::UniqueConnection in Connect statement.

                        C++, Qt, Qt Quick Developer,
                        PthinkS, Bangalore

                        1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @Sowmiya-R
                          Must be something in your Qt/compiler I guess ??
                          Can you try this test
                          https://www.dropbox.com/s/9eftxqghndn2bhw/myspinbox.zip?dl=0

                          S Offline
                          S Offline
                          Sowmiya R
                          wrote on last edited by
                          #15

                          @mrjj

                          I have tested your code.

                          I am able to reproduce the same in debug mode.
                          Can you please put a break point in slot function and run it in debug mode and see.

                          mrjjM 1 Reply Last reply
                          0
                          • S Sowmiya R

                            @mrjj

                            I have tested your code.

                            I am able to reproduce the same in debug mode.
                            Can you please put a break point in slot function and run it in debug mode and see.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            @Sowmiya-R
                            Ahh, now i see.
                            Yes the debugger seems to interfere with event loop so it does indeed call it twice on one click
                            if u place break point there. Else Not.

                            void MainWindow::on_doubleSpinBox_valueChanged(const QString &arg1)
                            {
                               static int hmm=0;
                                qDebug() << arg1;
                                hmm++;
                                qDebug() << hmm;
                            }
                            

                            "1,00"
                            1
                            "2,00"
                            2

                            I would guess that pausing it triggers the repeat feature and since it dont get an mouse release event its why.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Sowmiya R
                              wrote on last edited by
                              #17

                              I have developed a application using Qt, there regardless of debug mode or release mode value changed slot has called twice only on spinbox box up/down controls.
                              I try to reproduce the same in sample application, but its happening only in debug mode.

                              There is something missing in my application. I will check it out.
                              Thank you guys for you suggestions.

                              mrjjM 1 Reply Last reply
                              0
                              • S Sowmiya R

                                I have developed a application using Qt, there regardless of debug mode or release mode value changed slot has called twice only on spinbox box up/down controls.
                                I try to reproduce the same in sample application, but its happening only in debug mode.

                                There is something missing in my application. I will check it out.
                                Thank you guys for you suggestions.

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #18

                                @Sowmiya-R

                                But it ONLY happens for me if i set break point.
                                Never, ever else.

                                Do it happen for you if yo have NO break points ?

                                S 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @Sowmiya-R

                                  But it ONLY happens for me if i set break point.
                                  Never, ever else.

                                  Do it happen for you if yo have NO break points ?

                                  S Offline
                                  S Offline
                                  Sowmiya R
                                  wrote on last edited by
                                  #19

                                  @mrjj

                                  yeah!

                                  Without break point also its calling twice.

                                  mrjjM 1 Reply Last reply
                                  0
                                  • S Sowmiya R

                                    @mrjj

                                    yeah!

                                    Without break point also its calling twice.

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #20

                                    @Sowmiya-R
                                    Ok, that does not happen for me.
                                    Without break point it works correctly here.

                                    I have no idea what could be wrong with your Qt.

                                    Since you are using a clean project to test, i assume is something with your pc or Qt.

                                    1 Reply Last reply
                                    0
                                    • W Offline
                                      W Offline
                                      Wael11
                                      wrote on last edited by
                                      #21

                                      The double call to slot happened in my case only with a breakpoint in the slot function, otherwise it is called once only. The second call was triggered by a timer event

                                      JonBJ 1 Reply Last reply
                                      0
                                      • W Wael11

                                        The double call to slot happened in my case only with a breakpoint in the slot function, otherwise it is called once only. The second call was triggered by a timer event

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by JonB
                                        #22

                                        @Wael11
                                        For anyone reading this: This is known behaviour, which I stumbled across a long time ago and it was infuriating.

                                        With a QSpinbox Qt Internal code uses a timer on clicks/presses. If you step through in debugger you exceed the timeout and get bad/double behaviour.

                                        Simplest: change all connect() to QSpinbox click/key to pass Qt::QueuedConnection as last parameter for connection type, not default Qt::DirectConnection. Now you can use debugger breakpoints and all will be well. I wrote a method to connect all my spinboxes like this.

                                        1 Reply Last reply
                                        4

                                        • Login

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