Results 1 to 8 of 8

Thread: Differences in calling a Slot

  1. #1
    Join Date
    Feb 2009
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Differences in calling a Slot

    Hello,

    Is there a difference when you call a Slot?
    I connect a signal to a slot, the signal is handled when the object has time for it.

    I call the slot directly by: slotName();

    Is there a difference in the way the slot is being handled?
    Or is the slot handled in the same way as if it is called by a signal?

  2. #2
    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: Differences in calling a Slot

    If you are using a single thread then there is practically no difference.
    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.


  3. #3
    Join Date
    Feb 2009
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Differences in calling a Slot

    But what about threaded?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Differences in calling a Slot

    See the explanation in Qt::QueuedConnection. Notice that the receiving thread must be running an event loop.
    J-P Nurmi

  5. #5
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Differences in calling a Slot

    It depends on the last parameter in connect(): see Connection type.

    Ginsengelf

  6. #6
    Join Date
    Feb 2009
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Differences in calling a Slot

    I know how the connect function works :P

    The question was:
    Is there any difference when calling the slot directly? (So I do NOT use a signal or a connect)

    Example:
    Qt Code:
    1. void myClass::MyFunction()
    2. {
    3. if(something_happens)
    4. callAthreadsSlot(); //NO EMIT JUST CALL IT
    5. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Differences in calling a Slot

    Slots are normal functions in the sense that the meta-object compiler just generates some additional meta-data to be able to call slots dynamically by name at runtime. If you call a slot like a normal function, the function gets executed in the calling thread context. If you use signals and slots, the signal would get automatically queued by default if the sender and receiver live in different threads.
    J-P Nurmi

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

    Denarius (28th April 2009)

  9. #8
    Join Date
    Feb 2009
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Differences in calling a Slot

    Quote Originally Posted by jpn View Post
    Slots are normal functions in the sense that the meta-object compiler just generates some additional meta-data to be able to call slots dynamically by name at runtime. If you call a slot like a normal function, the function gets executed in the calling thread context. If you use signals and slots, the signal would get automatically queued by default if the sender and receiver live in different threads.
    Thank you. This was the answer I was looking for.

Similar Threads

  1. Replies: 12
    Last Post: 18th September 2008, 15:04
  2. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44
  3. Calling a slot with arguments
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 1st May 2008, 21:22
  4. menu actions calling a single slot
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2007, 19:19

Tags for this Thread

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.