I would not rather use timers, maybe some other solution?
I would not rather use timers, maybe some other solution?
of course your window will not be shown, because you enter in infinate loop before calling app.exec, try to rewrite code like this
but, anyway, this is useless code.Qt Code:
MainWindow w; w.show(); bool res = a.exec(); while(1){} return res;To copy to clipboard, switch view to plain text mode
take a look at QEventLoop.
btw why you can't use threads?
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
It's a bit complicated why I can't use threads but finally I figured out that I will not handle without themTimers are good but what about situation e.g. I have a function that stops program for some period of time waiting for response and with time interval set to 0 it can spoil the application I suppose, can't it?
Yes, but it will break it regardless if you use timers or not. Provided that you actually do something with the data you exchange with the server blocking the main thread will block your other functionality as well. Timers are the best approach in your case - threads will just make your application more complicated giving nothing in exchange.
Yes but in the other thread I'm just listening for data while in the main program I'm sending data to server. I think that this approach is better and easier than timers but I can be wrong.
No, I'm just printing it on a form. But I've tried it, I set timer interval to 0 and in trigged function I've inserted a socket recv function, which waits for data from server, but then I can't use a form because the application is suspend.
You need the main thread for that. If you block it, you won't see anything. So the argument against using timers because of a potential block is a killer also when using threads.
What for?But I've tried it, I set timer interval to 0
Use signals and slots. You don't need neither timers nor threads for accessing sockets.and in trigged function I've inserted a socket recv function, which waits for data from server, but then I can't use a form because the application is suspend.
Bookmarks