Quote Originally Posted by strateng View Post
I am having problems with when I click on a button which loops on lookforconnection() as it completely freezes the form but is running in the background. I would like to thread that function so that it just loops in the background and looks for connections.
Probably you are not going about this in the right way.

Consider starting a QTimer in your lookforconnection() function that you have connected to a “check for connection” slot. Each time the slot is triggered it checks for an available connection. If it finds one, it cancels the timer and does whatever you do when you find a connection; otherwise, it returns, leaving the timer to trigger the slot again at the defined interval.

If you just loop in another thread, it will still consume CPU (degrading performance of the GUI thread and other applications running at the same time), even though it won’t block the GUI thread entirely. That’s reasonable if you are doing actual computational work in the thread, but if you’re just polling for a desired condition, I suggest using a QTimer as described above instead. The extra thread won’t gain you anything but complexity.