Results 1 to 14 of 14

Thread: Signal response speed

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Signal response speed

    Hi,
    I want to know if the SLOT connected to a SIGNAL is executed just when the SIGNAL is emmited or there is a time between.

    I have a program that have a Thread that process images and emits signals like Images, Lines, Circles, ... then the main thread have a slot for every signal and paint them into a widget. Sometimes, if I start the program, stop it, start, stop, start, ... I see that some images are arriving too late.
    For example:
    The thread emits the image, process this image and when it is processing, it emits signals that correspond to lines, circles, ...
    Then when I stop and start the thread again, it seems that the lines and circles don't correspond to the image that is showing.

    It's a program that works fast and sometimes it can process 25 images per second.
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    A slot is immediately called when the corresponding signal is emitted. It might be drawing problem, not sure though.

  3. #3
    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: Signal response speed

    Quote Originally Posted by munna View Post
    A slot is immediately called when the corresponding signal is emitted. It might be drawing problem, not sure though.
    This is true only for signals where objects emitting and receiving are within the same thread. Otherwise signals are queued and slots are fired when control reaches the event loop in the receiving thread.

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    Hi,
    I know that the slot is queued if the emitting thread and reciver are different.
    Is there anyway to increase the main thread priority? I'm able to do it with different threads but I can't find how to do this with the main thread. Also I have searched to increase the process priority but don't find how.

    Thanks,
    Òscar Llarch i Galán

  5. #5
    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: Signal response speed

    What would increasing the priority change? That would slow down the worker threads slowing down signal emition. If you want to fire slots faster just make sure main thread doesn't do any long operations on its own (so that it can process the loop very quickly).

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    Hi,
    OK.
    The main thread don't does anything else that respose to the signals emmited by the thread.
    I will take a look at the thread code to see if there is any problem when I stop the thread.

    Thanks,
    Òscar Llarch i Galán

  7. #7
    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: Signal response speed

    If it doesn't do anything else then maybe you don't need worker threads at all?

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    Hi,
    Oh yes I need. I have 2 worker threads, one grabbing images from a webcam and another processing images from the buffer.
    Òscar Llarch i Galán

  9. #9
    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: Signal response speed

    Do you have a multiprocessor (or multicore) machine? If no, then there is no efficiency benefit from using threads.

  10. #10
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    Hi,
    I have a Pentium 4 with HyperThreading but I will change it to a multicore in a few months.

    I use threads because I don't want to freeze the main thread during image processing. Think that sometimes an image processing is about 2 or 3 seconds depending on the algorithm. This is why I have designed 2 threads, one grabbing images into a buffer and another one processing the images from the buffer.
    Òscar Llarch i Galán

  11. #11
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    I may be entirely off the mark here, but can't you set up your connections to be Qt::DirectConnection, even over different threads?

    Qt Code:
    1. connect(this, SIGNAL(signal()), that, SLOT(slot()), Qt::DirectConnection);
    To copy to clipboard, switch view to plain text mode 

    That way when you call the signal execution immediately jumps to the other thread's slot. Granted, this will remove some of the reason for using two threads to begin with, but it should still keep the GUI responsive.

  12. #12
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    Hi,
    Thanks for reply but it is not possible to make direct connections between differrent threads.

    Thanks,
    Òscar Llarch i Galán

  13. #13
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal response speed

    I double checked the documentation and you're absolutely right, you can't create a direct connection between two separate threads. If i understand the docs correctly, you should still be able to make a direct connection and access methods and memory in the other thread - while retaining execution control in the original thread. Well, you can but it's not safe since the other thread's event loop - if there is one - may access the same memory at the same time.

    From the documentation:
    With direct connections, the slot gets called immediately when the signal is emitted. The slot is executed in the thread that emitted the signal (which is not necessarily the thread where the receiver object lives).

    Be aware that using direct connections when the sender and receiver live in different threads is unsafe if an event loop is running in the receiver's thread, for the same reason that calling any function on an object living in another thread is unsafe.
    But please, correct me again if i'm wrong. Thanks

  14. #14
    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: Signal response speed

    In such situations I always suggest to ask yourself a question "do I really need it?", so do you really need "instant" slot responses? Is it just a thing you'd like to have or are you convinced it is crucial to the functioning of the application?

Similar Threads

  1. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 10:10
  2. Replies: 2
    Last Post: 17th May 2006, 21:01
  3. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 15:17
  4. send signal from QCombobox
    By raphaelf in forum Qt Programming
    Replies: 22
    Last Post: 28th February 2006, 14:18
  5. No such signal...
    By chaimar in forum Qt Programming
    Replies: 12
    Last Post: 24th January 2006, 22:33

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.