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?