Yes, of course you have to create a custom event.
Don't forget to give it an id greater or equal that QEvent::User.
You can add some extra members to your subclass to hold the progress data and whatever you may need.
Yes, of course you have to create a custom event.
Don't forget to give it an id greater or equal that QEvent::User.
You can add some extra members to your subclass to hold the progress data and whatever you may need.
See the attached example.
J-P Nurmi
Valheru (12th June 2007)
I'm not sure if a solution has been found yet, but maybe you could simply keep a single global object to which to connect signals/slots. This could be a global variable or a singleton object or something similar. You can control that object from your static function.
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
I think that was already suggested in the other thread. From what I've read here, the solution with posting a custom event I find most appealing as you don't need a "sender" object for that.
Using a global object should work but at the same time violates some rules of good design, while the solution using events directly seems to be ok.
Probably not, but since I am doing it "along side" my work, my concentration can span so muchWas my explanation that bad?![]()
Well, in C++ you have to make sure the function is thread safe - that means - that there is no situation where two threads are trying to access the same reasorce at the same time.In Java I can simply use a public function with no ill effects between threads - is that possible with QThreads? Or should I set up some round-robbin thread/slot implementation?
You should use mutex or semaphores to protect the mutual excluded code.
I too vote for the custom event solution, its the "cleanest".
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
In Java you have to do the synchronisation as well of course... It's not as simple as calling any function doing anything you want anywhere you want.
Sorry I didn't update this thread sooner. I did indeed solve it by subclassing QCustomEvent. In the end the solution was simple to implement, and works very well. Thank you all for your help and patience.
/edit : the crash was being caused by accessing a function running in another thread directly. It was solved by bundling the data in the subclassed QCustomEvent as suggested.
Bookmarks