[quote author="yan bellavance" date="1311786486"]You have to be carefull when people tell you not to call a function because it's "dangerous". If we listen to them then we cannot call: QCoreApplication::processEvents(), QThread::sleep(), QObject::moveToThread() or others I have not read of. They say this because of the context in which they are programming, they have guidelines that limit what they can do.[/quote]
This thread has NOTHING to do with those methods. And nobody said that it's dangerous. Only that they lead to bad/fragile code.
Of course you should never call sleep() in the GUI main thread (if you don't moveToThread() your QThread then it's still in the main thread and then I would see why calling sleep should be avoided) and if you call processEvents(), do it from the GUI main thread preferably.
... you CAN'T call QThread::sleep from the main thread, since you don't have access to that QThread protected sleep() ...
I built a qt app on Linux that uses all of these and it's been running for a year now without ever crashing. Also, my app often show its CPU usage as 0% in the system monitor (on windows this would be windows task manager),its very efficient. I do have an i7 intel cpu.
And we're talking about Windows.
[quote author="yan bellavance" date="1311786693"]
[quote author="peppe" date="1311661270"]Well, do you know of a better API you can use instead of Sleep()? You could patch QThread::sleep () and submit a MR :)[/quote]
if you want to let the GUI to keep doing its while it waits then call QCoreApplication::processEvents()
if you really need to sleep because you have other code you want to run then just do it in a qthread and call moveToThread. I have done it and it works very well.[/quote]
This reply is nonsense -- I was talking about QThread::sleep resolution on Windows. That is, the OP's issue.
KDAB (UK) Ltd., a KDAB Group company