Results 1 to 11 of 11

Thread: what is better signal or constructor passing parameter to thread performance wise?

  1. #1
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default what is better signal or constructor passing parameter to thread performance wise?

    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 ?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    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.

  3. The following user says thank you to ChrisW67 for this useful post:

    toufic.dbouk (13th September 2013)

  4. #3
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    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.

  5. #4
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    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:
    1. workerObject *wObject = new workerObject;
    2. QThread *qThread = new QThread;
    3. wObject->setupAtt(num1,num2);
    4. wObject->moveToThread(qThread);
    5. 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 18:03.

  6. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    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,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    toufic.dbouk (15th September 2013)

  9. #7
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    Alright thanks for the clarification.
    Best Regards.

  10. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    Quote Originally Posted by anda_skoa View Post
    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,
    _
    until another programmer comes a along...

    Simple setters are not always self-documenting
    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.

  11. #9
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    Quote Originally Posted by amleto View Post
    Simple setters are not always self-documenting
    a setter method wouldn't bother a lot though.
    mmmm... what would do you recommend then ?
    your first answer wasn't clear so i edited the post ( check the previous posts )

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    Quote Originally Posted by toufic.dbouk View Post
    a setter method wouldn't bother a lot though.
    mmmm... what would do you recommend then ?
    Amleto would suggest a constructor or a setter method with proper thread synchronisation (google if not familiar with the term, it's not Qt specific).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #11
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is better signal or constructor passing parameter to thread performance wise

    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.

Similar Threads

  1. Passing 2d array as parameter
    By Archa4 in forum Newbie
    Replies: 9
    Last Post: 7th February 2011, 15:36
  2. Replies: 4
    Last Post: 12th August 2008, 02:55
  3. Replies: 3
    Last Post: 17th July 2008, 08:43
  4. Passing Ui files as parameter
    By hgedek in forum Newbie
    Replies: 3
    Last Post: 12th December 2007, 13:14
  5. Passing QFile objecrt as parameter
    By db in forum Newbie
    Replies: 2
    Last Post: 28th August 2007, 17:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.