PDA

View Full Version : Rotary encoder driver in Qt



vanduongbk
12th January 2015, 07:34
hi all everyone
i have register a rotary encoder in /dev/input/event1, and when i read it by evtest as belows:
Supported events:
Event type 0 (Sync)
Event type 3 (Absolute)
Event code 0 (X)
Value 0
Min 0
Max 24
Flat 1
Testing ... (interrupt to exit)
Event: time 1421072947.095573, type 3 (Absolute), code 0 (X), value 1
Event: time 1421072947.095603, -------------- Report Sync ------------
Event: time 1421072948.625644, type 3 (Absolute), code 0 (X), value 2
Event: time 1421072948.625644, -------------- Report Sync ------------
Event: time 1421072949.476578, type 3 (Absolute), code 0 (X), value 3
Event: time 1421072949.476578, -------------- Report Sync ------------
Event: time 1421072949.689086, type 3 (Absolute), code 0 (X), value 4
Event: time 1421072949.689116, -------------- Report Sync ------------
Event: time 1421072953.076890, type 3 (Absolute), code 0 (X), value 3
Event: time 1421072953.076890, -------------- Report Sync ------------
Event: time 1421072953.904663, type 3 (Absolute), code 0 (X), value 2
Event: time 1421072953.904663, -------------- Report Sync ------------

and I want using with an event in Qt ,how I can work well?

d_stranz
12th January 2015, 19:48
Wrap the code that handles your encoder events in a Qt / C++ class derived from QObject. Add a custom signal ("encoderEvent" maybe) that contains the parameters you want to read from the encoder. Each time your handler receives an event from the encoder, emit the signal with the parameters you have received.

vanduongbk
13th January 2015, 02:06
hi d_stranz's ,
i have emit signal from a event above but it's emit to all form ,both mainform and childform( is child of main when press button on main) ,
i only want that when open 1 active form ,it's only emit to 1 form

d_stranz
14th January 2015, 00:14
Signals are handled only if you connect them to a slot in your GUI. If you don't want a signal handled by a child, then don't connect it to a slot in the child.

Since you haven't posted any code, it is impossible to tell what you might have done wrong.