Hello team,
i was wondering what is better performance wise, to send a QString through constructor of class sub classing QObject( worker thread ) or through emitting a signal holding the QString as a parameter to the worker thread ?
Hello team,
i was wondering what is better performance wise, to send a QString through constructor of class sub classing QObject( worker thread ) or through emitting a signal holding the QString as a parameter to the worker thread ?
If you are able to meet your requirement by passing a string once to the constructor then you would only be setting the string once by slot and the difference is absolutely not worth considering.
toufic.dbouk (12th September 2013)
Thanks for the reply chrisW67
i kinda knew that but i wanted to make sure of it
yea im just passing 2 String , so ill pass them through the constructor and set them later in the class sub classing QObject as a worker thread.
Hey there,
what about just making a function in the worker Thread sub classing QObject and call it
num1, num2 are inputs from the GUI thread
like ( just a sample code) :
passing num1,num2 through a function in wObject class
wObject is instance of a class sub classing QObject
qThread is an instance of QThread
Qt Code:
workerObject *wObject = new workerObject; wObject->setupAtt(num1,num2); wObject->moveToThread(qThread); qThread->start();To copy to clipboard, switch view to plain text mode
sample 2:
emiting a signal from main GUI holding num1 , num2 and ctach it in the wObject class
sample 3:
just pass num1 , num2 through the constructor of wObject
instead of signals or passing it through constructor
its not a technical problem, im just asking what is better to do
hope that clarifies it and read the previous posts if its still not clear
Thanks.
Last edited by toufic.dbouk; 15th September 2013 at 17:03.
it's not very clear which thread that should be called from and and you don't state how thread-safe that method will be.
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'd say either pass in constructor or call the setter method before you hand the worker object off to the thread.
Both of those variants don't need any protection against concurrent access since there is only one thread involved at the time.
Cheers,
_
toufic.dbouk (15th September 2013)
Alright thanks for the clarification.
Best Regards.
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.
im aware of the term, i usually code in Java and use synchronization in order to ensure that threads accessing the same variable or class execute properly so that one thread doesn't see half of a change done and execute upon it ensuring thread safety, atomic operations, avoiding deadlock, missing an update of value etc...
in other words , so that threads have a mutual exclusive execution or access of a critical section.
Bookmarks