0

I'm writing a simple test application with a Qt5 GUI that should be able to open a /dev/input/eventX file to read events and list the events it finds in the Qt UI. I should say that I have basically no experience with Qt5, so I'm sure it's just that Qt has some way of doing this and I'm not using it correctly.

The problem is that I'm trying to implement the reading of the /dev/input/eventX file in a pthread that is created in the constructor of the QMainWindow class for the GUI. As of right now, the application works, sort of... when I launch the application through QtCreator, the UI shows up, but when I tap the screen to try to generate an event, nothing shows up in the console output, where my log messages displaying the event codes should be.

However, when I launch the application from command line, as it needs sudo access to be able to read from /dev/input/eventX in the first place, it blocks the command line and will display the events as expected in the console as I tap the screen, but the GUI never shows up.

So it looks like the pthread is blocking the GUI? In the constructor, I have the following two lines for pthread creation:

pthread_create(&t_touch, NULL, &touchPoll, NULL);
pthread_join(t_touch, NULL);

Where t_touch is the pthread_t object that is a member of the main window class. Touch poll is the function that does the polling, which had to be made global, separate from the main window class because if I made it part of the class, the only way to get the syntax to work correctly was to have a static helper function to call the touchPoll method, since there is a problem with the this context when it comes to function pointers. Of course, this makes it so my polling method can't access the main window if I want to pass information to it based on the events raised...

Unfortunately C++11 and higher aren't an option since my team can only use C++98 for projects. Does anyone know what the issue with the UI is? Is the pthread just blocking it? Is there some built-in Qt class I should be using instead?

Darin Beaudreau
  • 375
  • 7
  • 30
  • 1
    If you are using Qt, thhen use QThread, not pthreads. Don't mix. – Jesper Juhl May 28 '19 at 19:41
  • 1
    Why do you join the thread immediately after starting it? Do you understand what [`pthread_join`](http://man7.org/linux/man-pages/man3/pthread_join.3.html) does? – G.M. May 28 '19 at 19:51
  • @G.M. I hadn't looked into it in that much detail yet. I was working off of an example since I haven't used pthreads since my Operating Systems class more than 3 years ago. I also haven't used C++ in almost as long, so a lot of this is just fumbling around trying to make it work. – Darin Beaudreau May 28 '19 at 19:56
  • "fumbling around" is usually a *really bad* way to learn C++ and also threads. Dedicated studying (with [a good book or two](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)) and a couple of years of practice on top of that, is likely to lead to better results. – Jesper Juhl May 28 '19 at 20:01
  • @JesperJuhl I'm aware, but the touchscreen I'm using to test this is being loaned to us, and I don't have all the time in the world to verify whether or not I can make it work. The problem is we run Scientific Linux 6.4 (linux kernel 2.6.32) which doesn't support multi-touch touchscreens, but the events are still showing, so I'm writing my own parser to see if it's possible to still use it for our purposes. Also, I'm not "new" to C++ or threads. I've used it extensively in the past, it has just been years since I've used it for anything. – Darin Beaudreau May 28 '19 at 20:06

0 Answers0