This is probably more a question about programming methods than an request for getting some specific code going. Bear in mind I have come from an embedded programming background which is very much run to complete software.
I have finished a little Qt4 C++ program that sends and receives serial data for programming embedded microcontrollers. I send out little packets of data over a USB virtual com port (the virtual com port sends and receives data in exactly the same way as a normal ttySx com port).
Now, I have a big array of memory content that I parse and then send out 16 bytes at a time with a checksum. I then wait for an acknowledgement byte back from the microcontroller. When I say wait, I really mean wait. The program is just stuck in an endless loop waiting for the ack byte.
I am sure that, apart from the fact that if no serial message comes back, this is just not the way to write PC programs. In an embedded routine I would either have a timer go off if nothing was received and report an error or be calling a serial handling routine from my main loop. There doesn't seem to be this main loop way of writing code in PC based GUI applications.
It seems in C++ global variables are really frowned upon. I could, I suppose, have a timer go off and check the routine that does all this parsing and handling, going through this large state machine a stage at a time, but I think that would necessitate having loads of global variables.
Is it easy either to explain or point me to an article on how this is done in this sort of application (it's using KDevelop and Qt4)? I have tried Googling around, but it's such a verbose question it doesn't work too wll in a search engine!
Many thanks.