QDoubleSpinBox valueChanged has called twice
-
Qt 5.15.0 Release Win32
①、when I call on_nudBm3d_valueChanged(), this function will call twice.
void QtImageProcessing::on_nudBm3d_valueChanged() { if (checkQImage(image1)) { cv::Mat src = QImageToMat(image1); cv::Mat dst; int64 t1 = cv::getTickCount(); cv::xphoto::bm3dDenoising(src, dst, ui.nudBm3dH->value(), ui.nudBm3dTemplateWindowSize->value(), ui.nudBm3dSearchWindowSize->value(), ui.nudBm3dBlockMatchingStep1->value(), ui.nudBm3dBlockMatchingStep2->value(), ui.nudBm3dGroupSize->value(), ui.nudBm3dSlidingStep->value(), ui.nudBm3dBeta->value()); int64 t2 = cv::getTickCount(); showImageInPicturebox2(MatToQImage(dst)); qDebug() << QTime::currentTime() << qPrintable(" QDoubleSpinBox value: ") << ui.nudBm3dH->value(); qDebug() << qPrintable("cv::xphoto::bm3dDenoising(): ") << (t2 - t1) / cv::getTickFrequency() * 1000 << qPrintable(" ms"); } }
②、if I change code to below, only call one time.
void QtImageProcessing::on_nudBm3d_valueChanged() { if (checkQImage(image1)) { cv::Mat src = QImageToMat(image1); cv::Mat dst; int64 t1 = cv::getTickCount(); //do nothing... int64 t2 = cv::getTickCount(); showImageInPicturebox2(MatToQImage(dst)); qDebug() << QTime::currentTime() << qPrintable(" QDoubleSpinBox value: ") << ui.nudBm3dH->value(); qDebug() << qPrintable("cv::xphoto::bm3dDenoising(): ") << (t2 - t1) / cv::getTickFrequency() * 1000 << qPrintable(" ms"); } }
-
Looks like your value has increased from
1.1
to1.2
?! Is there only oneQDoubleSpinBox
? Are other spinBoxes connected to that slot?
The OCV function shouldn't change that value directly, so it must change because of something else.Debug line by line and see what happens exactly.
Edit:
Does
showImageInPicturebox2(MatToQImage(dst));
ORcv::xphoto::bm3dDenoising(src, dst, [ . . . ] )
change your GUI and / or member var values (especiallyui.nudBm3dH->value
), so thaton_nudBm3d_valueChanged()
is called again ? -
@Pl45m4 My GUI has 6 QSpinBox and 2 QDoubleSpinBox , all connect to on_nudBm3d_valueChanged() ,when I changed any QDoubleSpinBox or QSpinBox value, valueChanged called twice, value will changed twice too.
showImageInPicturebox2() and cv::xphoto::bm3dDenoising() can't change GUI SpinBox value.
cv::xphoto::bm3dDenoising() is a slow function , if I change it to another fast function ,valueChanged only call one time. -
-
I don't see what this bugreport should fit to your problem... you most likely have some signal/slot loop when one spinbox changes it's value and emits a signal which is then connected to another spinbox. Provide a compilable example if you think it's a bug in Qt.
-
I'm certain if valueChanged cost 500ms or more,valueChanged will call twice, and SpinBox value also increase twice. There is any timer use inside SpinBox?
I change Win32 to X64, cv::xphoto::bm3dDenoising() use 400ms, and valueChanged() only call one time. -
@Christian-Ehrlicher I do not have enough privileges to upload file.
void MainWindow::on_doubleSpinBox_valueChanged(double arg1) { Sleep(600); qDebug()<<"called..."; }