[Qt-interest] duration of a keypress?

Arnold Krille arnold at arnoldarts.de
Sat Dec 5 21:24:55 CET 2009


On Saturday 05 December 2009 17:07:41 Chris G wrote:
> Hello all,
> I need to get the duration of time between a key press and release.
> The problem is that there may be code run in between the two events
> which block the main thread for a long time.  If I just look at the
> time between keyPressEvent and keyReleaseEvent being called, it will
> not be the same as the duration that the key was actually pressed, it
> may be much longer.
> So is there a qt-way to get this information?

There is a Qt-way for this: Don't block the main-thread. If you have heavy 
work to do, either split the loops into slots scheduling themselves via 
QTimer::singleShot or let a worker-thread do the job. QRunnable is probably 
what you are looking for to run a single function in its own thread.

When the gui isn't blocked by long-running functions, starting a timer in 
mousePressEvent and stopping it in mouseReleaseEvent should be pretty 
accurate.

You are not trying to get double-clicks?

Have fun,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091205/d6c45fb7/attachment.bin 


More information about the Qt-interest-old mailing list