PDA

View Full Version : Problem with QSlider's signal



lni
17th September 2011, 09:50
Hi,

I have a slider with valueChanged signal connecting to a quick computation.

When I move the slider crazily fast. I have to call QCoreApplication::processEvents() to immediately update the slider movement, then emit valueChanged.

The computation can't catch up the speed and not all valueChanged's are received.

However, when I stop sliding, it starts to process those singals and end up the last slider value doesn't much the computation result.

For instance, I finally stop at value 53, but the computation process the previous missed signal, such as 32. So the last input slider value doesn't match the computation.

How can I solve this problem?

Thanks!

Hi,

I have a slider with valueChanged signal connecting to a quick computation.

When I move the slider crazily fast. I have to call QCoreApplication::processEvents() to immediately update the slider movement, then emit valueChanged.

The computation can't catch up the speed and not all valueChanged's are received.

However, when I stop sliding, it starts to process those singals and end up the last slider value doesn't much the computation result.

For instance, I finally stop at value 53, but the computation process the previous missed signal, such as 32. So the last input slider value doesn't match the computation.

How can I solve this problem?

Thanks!

Added after 24 minutes:

It looks like I solve it!

In computation, I did



if ( slider->value() != value ) {
return;
}


Wonder if this is the right way...

amleto
17th September 2011, 11:24
no, the computation shouldnt be in the gui thread. then you wont need to worry about processevents

lni
18th September 2011, 11:38
no, the computation shouldnt be in the gui thread. then you wont need to worry about processevents

Actually, I am using QtConcurrent::map() in my computation, which is in other threads. That is why I have to processEvent to update the slider movement immediately...

Now, I just spend 12 hours to find a crash when doing fast moving in Windows, but no crash in Linux.

I should be using QCoreApplication::sendPostedEvents(), not QCoreApplication::processEvents().

Can you believe it took me 12 hours for me to find that darn 1 line difference!

It keeps complains "Qt has caught an exception thrown from an event handler. Throwing exceptions from an event handler is not supported in Qt. You must reimplement QApplication::notify() and catch all exceptions there."

I did re-implement notify and caught the exception, but it still crashes no matter I return true/false after exception! I had also searched all over the world and downloaded Microsoft's useless Application Verifier for nothing!

amleto
18th September 2011, 12:44
so what was throwing?

syclopse
20th September 2011, 07:18
Qt is smart enough and fast to catch the each and every value change event,
so that is not with Qt that it is missing any value change event.
please check your code there might be some critical code that make Qt behave like that,
otherwise even single value change event is caught by Qt,
so do 1 thing make a sample program with slider and check only the functionality what you want with slider in that sample app.

lni
21st September 2011, 15:11
so what was throwing?
Don't know. I try to catch
std::exception, QString, QtConcurrent::Exception, QtConcurrent::UnhandledException, std::string, con char*, none of them caught it, it is caught by catch( ... ) and then die with the complain...

amleto
21st September 2011, 19:29
I suggest you debug it and turn 'break on exceptions' on.