We're trying to program a joystick reader on Red Hat Enterprise Linux 6.1.

The file being read is /dev/input/js0, it's a file that is created by Linux and joystick drivers when a joystick is plugged in. If you have multiple joysticks, there'd be js1, js2, js3... etc. etc. We're only ever going to have 1 joystick plugged in.

We're trying to avoid a while(true) loop that just constantly reads the file in a blocking state. The last time I posted something about this I got the suggestion of:

"Just use QSocketNotifier or QLocalSocket on /dev/input/js0"

We've been reading the documentation on these 2 classes, but we can't seem to get these to work.

So we have these members in a class:

Qt Code:
  1. FILE* fileReader;
  2.  
  3. QLocalSocket* fileSocket;
  4.  
  5. QSocketNotifier* fileSocketNotifier;
To copy to clipboard, switch view to plain text mode 

And in the constructor, they get initialized to:

Qt Code:
  1. // Try to open the file
  2. fileReader = fopen( FILE_STRING.toStdString().c_str(), "r" ); // Where FILE_STRING = /dev/input/js0
  3. int fd = fileno( fileReader );
  4. fileSocket = new QLocalSocket(); // What does this class do?
  5. fileSocket->setSocketDescriptor( ( quintptr ) fileReader ); // What is this class for? How do I use this with the Notifier?
  6. fileSocketNotifier = new QSocketNotifier( fd, QSocketNotifier::Read ); // Is this how you initialize this class?
To copy to clipboard, switch view to plain text mode 

So... is there any good examples of simply opening/connecting to a socket and being able to read from it? I've Googled this but I usually end up back in the QT Documentation for it, which doesn't really provide examples for opening a socket, it just says socketNotifier( YOUR_MAGIC_SOCKET_NUMBER_HERE, otherStuff );

Yea.. I'm lost.

Any help would be appreciated.