PDA

View Full Version : How to delay program close to allow time for functions to finish



TonyInSoMD
31st August 2018, 12:30
I have 2 qt programs, they are two separate qApps. I use QTcpServer and QTcpSocket on localnet so that they can talk to each other and simulate a network. They are actually going to run on a real TcpIP network with a server computer and client computers when it's finished, but I only have one computer to work with for development and testing. Using localnet with different ports is the only way I could think of to simulate it. How they expect me to develop a network program without a network for testing with is beyond me, but I have to make do with what they give me. Government job (I'm thinking of leaving because of this kind of crap, plus they treat contractors like trash. I would use stronger, more accurate language, but this is a family friendly environment :)). In the real world, when the client gets locked, the server will still be running, and I think under those conditions it will work great, but I have no way of verifying it. I've been using qDebug to find out what's happening and at what time when it locks/unlocks. The problem is the server hits the lock event and stops before the client even hits the lock event much less process and send the data. How can I delay the server program from stopping until after it reads and processes the data that was sent to it? The client keeps running until the function I call finishes (6 ms), so I'm 99% sure that part of the program is working as designed. I think if I could put some kind of delay function in the lock event that doesn't stop other functions from running, that would work. I think 1 second would be way more than enough. I think there might be a way to use QWaitCondition to accomplish this, but I don't seem to be able to figure it out. I found solutions on line, but posts after the "solution" all say don't do it that way, it could cause cpu lock. BUT they don't offer an alternative.

Added after 1 27 minutes:

Forget this post, I found out the server has to run with the computer in lock screen, so I have to find a way to make the sever and client run as a service. Lucky me. If anyone has any ideas on that one, I'm all ears but I'm not expecting an answer since it has nothing to do with this post. There used to be a way to do it with Qt, but it only works with XP, nothing from Vista and up.