Need advice on usage of qextserialport class before the QApplication event loop
Hi,
I have a requirement of sending serial commands and accept the response using qextserialport library on Qt4.
I am trying to read/ write to/from the serial port using signals and slots mechanism. There are series of commands that need to be sent in-order to initialize the setup. For all the commands i send , i need to check for an acknowledgement. So, decided to define the Qtimer for a timeout. Both the Qtimer and the Qextserialport are using the signal and slots. The serial port read/write has to be done before the Qapplication event loop. As per my understanding of Qt, I presume, Signals and slots does not work without an event loop.
Any suggestions on how to use the serial port library would be grateful.
Thanks
Re: Need advice on usage of qextserialport class before the QApplication event loop
Quote:
Signals and slots does not work without an event loop.
That's correct.
Quote:
The serial port read/write has to be done before the QApplication event loop.
This probably can't be done if the serial port class depends on a running event loop. QTimer won't work without an event loop either.
I am sure what you want to do can be done after the event loop is started. If what you are trying to do is to perform the serial port setup before the main GUI becomes visible, that is certainly possible. Instead of calling mainWindow.show() just before the call to app.exec() in main(), define a different MainWindow slot that will handle your setup. Call that slot from main() instead. As soon as the event loop starts (app.exec()), that slot will be called. Do your setup in there. Define a signal for MainWindow that gets emitted after the setup is done, and connect that signal to the QMainWindow::show() slot.