Qt DoubleSpin Box value changed slot has called twice
-
Hi Everyone,
I am using Desktop Qt 5.5.0 MSVC2013 64 bit.
I have created a QT widgets Application project.
I have added one Qt double spin box in form ui and created value changed(Qstring) slot function.
Single step value is set 1 for the double spin box.
I ran the application.
Now the problem is, if i press Keyboard up/down key or mouse scroll up/down button, the slot has executed once
but if I click Qt doublespinbox up/down control, the value change slot has executed twice.
So doublespin box single step value is incremented twice.if you are not able to reproduce the problem, run it in debugging mode put a break point in slot function and run.
I looking for some help to solve this problem
Thanks,
Sowmiya -
@Sowmiya-R said in Qt DoubleSpin Box value changed slot has called twice:
if you are not able to reproduce the problem, run it in debugging mode put a break point in slot function and run.
so did you compare the stack-traces of the two calls?
Then it should be pretty clear what causes the 2 calls. -
@raven-worx
ya, I have checked the stack traces.
both call has same traceson_doublespinbox_valuechaged()
qt_static_metacall
qt_metacallThanks,
Sowmiya -
@Sowmiya-R
then you probably have done the connection to the signal twice. -
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.
-
@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. -
-
@Sowmiya-R
simply try to rename theon_doublespinbox_valuechaged()
slot -
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 -
@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? -
Hi
Tried with 5.5.1 in default GUI project
Cannot reproduce.
-
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; }
-
@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 -
@Sowmiya-R ,
Hi,
You can use Qt::UniqueConnection in Connect statement. -
@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"
2I would guess that pausing it triggers the repeat feature and since it dont get an mouse release event its why.
-
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. -
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 ?
-
@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.