[Qt-interest] strange behavior of spinbox when sleeping (Linux only)
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Mon Nov 22 06:21:53 CET 2010
I can confirm this issue with QT 4.7.0 on Linux (Ubuntu 10.10) as well.
Though I'm seeing the slot getting called THREE times for each mouse
click! The behaviour with keyboard is same (and proper) i.e 1
increment for each key-press.
HTH,
-mandeep
On Sat, Nov 20, 2010 at 8:58 PM, TP <paratribulations at free.fr> wrote:
> Hello,
>
> I obtain a strange behavior of QSpinBox when connecting its "valueChanged(
> int )" signal to a method that "sleeps" for some time: for one click on the
> increase and decrease arrows of the spinbox, the method is called two times
> instead of one, and the spinbox number is incremented or decremented by two
> units instead of one. Strangely, when using keyboard arrows, the problem
> disappears.
> When using a for loop (see commented code) instead of a sleep(), the problem
> disappears too.
>
> I have obtained this with Qt C++, PyQt, and PySide on Linux.
> I have not been able to reproduce it with PyQt on Windows (I have not tested
> the C++ and PySide version on Windows).
> So this problem seems to appear only on Linux.
> My Qt version: 4.6.2.
>
> Can you reproduce this behavior on Linux?
> Have I to enter a bug report?
>
> Additional question: what is the origin of the sleep() function used below?
> I am not familiar to C++. Is it the POSIX thread library (available only on
> Linux: "man pthreads")?
>
> Julien
>
> //// spinbox.hpp
> #include <QtGui>
> #include <QtCore>
>
> class MyObject: public QObject
> {
> Q_OBJECT
>
> public slots:
> void wait_a_moment( void );
> };
>
> //// spinbox.cpp
> #include "spinbox.hpp"
>
> void MyObject::wait_a_moment( void )
> {
> qDebug() << "calculation begin";
> sleep( 1 );
> // for ( int i=0; i<100000000; i++ )
> // {
> // if ( i%10000000 == 0 )
> // qDebug() << i;
> // }
> qDebug() << "calculation end";
> }
>
> int main( int argc, char * argv[] )
> {
>
> QApplication app( argc, argv );
>
> MyObject * myobject_instance = new MyObject();
>
> QDialog * dialog = new QDialog();
> dialog->resize( 750, 550 );
>
> QSpinBox * spinbox = new QSpinBox( dialog );
> QObject::connect( spinbox
> , SIGNAL( valueChanged( int ) )
> , myobject_instance
> , SLOT( wait_a_moment() ) );
>
> QVBoxLayout * vboxlayout = new QVBoxLayout( dialog );
> dialog->setLayout( vboxlayout );
> dialog->show();
>
> app.exec();
> }
>
> //// spinbox.pro
> HEADERS += spinbox.hpp
> SOURCES += spinbox.cpp
>
>
> //// Compilation
> $ qmake
> $ make
>
>
> --
> python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
> 9&1+,\'Z4(55l4('])"
>
> "When a distinguished but elderly scientist states that something is
> possible, he is almost certainly right. When he states that something is
> impossible, he is very probably wrong." (first law of AC Clarke)
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list