what you are doing is even worse than subclassing QThread (not that subclassing QThread is bad)
You are blocking the main thread with the while(...) loop in MyObject.
what you are doing is even worse than subclassing QThread (not that subclassing QThread is bad)
You are blocking the main thread with the while(...) loop in MyObject.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
well, now that you have changed it to QMetaObject::invokeMethod with your edit it should be a lot better...
Now you're just blocking the other thread with that while(...)
You know it would be handy if you didn't hide code that is directly relevant to your question.![]()
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
sorry for that.. your footnote really make sense
Do you have any idea why the signals from timer are not processed during the doWork()? They start to be processed after i try to finish _myThread with _mythread->wait(). :/
I cant find any good way to let the timer work in a separate thread.![]()
how many times do you think I shall say that your while(...) is* blocking before you will think that might be the cause?
*guessing since you are still hiding that code...
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
One with some additional comment would be enough.
So how to avoid this devilish while(..) and still do some processing loop that can coexist with the timer in harmony?
use signals and slots. not while(true) or equivalent
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
My doWork() is processing some number of items. It should process this data unless user presses Pause button or Stop button. I initially made a QThread subclass which in run() had while(true) (i guess that this is not a bad practice in thread?) and some exit conditions checking flags set by signals from GUI. As "this->moveToThread(this)" trick is not a good thing to do i have rebuild my QThread subclass to QObject subclass.
How would you rebuild the while(true){} processing loop to fit "QObject moved to QThread" approach?
Best regards.
How do you expect me to say how you can refactor your while loop when you have given no information about what it actually does and where the input comes from
I give up. Just use this.
http://doc.qt.io/qt-4.8/qcoreapplication.html#processEvents
Last edited by amleto; 4th August 2012 at 15:45.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
If you suggest to use:
it does not solve the problem.Qt Code:
doWork() { (...) while(true) { (...) }To copy to clipboard, switch view to plain text mode
read my sig
All your timer does is send signal. you can put your timer anywhere. Why does it have to be in heavy processing thread?
Last edited by amleto; 4th August 2012 at 15:57.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
I can redesign and put a timer outside the processing thread. Still for my own knowledge i would like to know it there is a way of installing the QTimer inside a Thread.
Sorry for not pasting the original code. It is not my property and i cannot share it. As it is quite big i just tried to extract the highlights.
Bookmarks