Results 1 to 10 of 10

Thread: Signal/slot responsiveness

  1. #1
    Join Date
    Mar 2010
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Signal/slot responsiveness

    Testing QClipboard class, i wrote:

    Qt Code:
    1. clipboard = QApplication::clipboard();
    2. connect(clipboard, SIGNAL(changed(QClipboard::Mode)), this, SLOT(clipboardChanged()));
    To copy to clipboard, switch view to plain text mode 

    After an initial proper behavior (10-15 times clipboardChanged slot called after every data change ), app stops working (clipboardChanged not called anymore ).
    Any suggestions are greatly appreciated.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal/slot responsiveness

    Have you tried dataChanged instead ?

  3. #3
    Join Date
    Mar 2010
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal/slot responsiveness

    Of course, but had same behavior. The app is an extremely simple clipboard manager that runs in background. After a while (20-30 mins - sorry, can't be more specific, different behavior every time...) app stops working.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Signal/slot responsiveness

    The whole application "freeze" or only that slot isn't executed after some time?

    In the first case it "smells" like a memory leak, look for resources that allocate 'temporary' memory on the heap, every time that slot is called or with the part of your app that emit the signal.

    And in the second look at your variables, they might go out of scope

  5. #5
    Join Date
    Mar 2010
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal/slot responsiveness

    The second case.
    The signal
    Qt Code:
    1. void QClipboard::changed(QClipboard::Mode mode)
    To copy to clipboard, switch view to plain text mode 
    is emitted by the system, and no variable is involved in the signal/slot process.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal/slot responsiveness

    You shouldn't depend on this signal happening when the application is in the background, particularly on MacOS.

    If you click on your application window (If it doesn't have one, create one for this test), does it start to work again?

  7. #7
    Join Date
    Mar 2010
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal/slot responsiveness

    void QClipboard::dataChanged ()
    On Mac OS X and with Qt version 4.3 or higher, clipboard changes made by other applications will only be detected when the application is activated.
    This is the reason why i used changed() instead of dataChanged(). However, clicking on the application window (activating it) doesn't solve the problem.

  8. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Signal/slot responsiveness

    See that "clipboard" or "this" variables don't go out of scope. ("this" is the main window?).
    I think that if you describe where/how do you create those variables, we will be able to give better advices.

  9. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal/slot responsiveness

    'this' is a C++ keyword. It's not likely to go out of scope :-)

    'clipboard' is a pointer to the application global clipboard. Even if it goes out of scope, the original pointer assigned to it will not, so for the purpose of the connect call, it will remain valid for the lifetime of the QApplication object.

  10. #10
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Signal/slot responsiveness

    You are right about clipboard, sorry, my bad

    But "this" is a pointer to the class instance and if the class instance gets destroyed... this can be a possible cause of that behavior, and i don't see any other...

Similar Threads

  1. Signal and slot
    By jayreddy in forum Qt Programming
    Replies: 12
    Last Post: 15th December 2009, 05:05
  2. SIGNAL and SLOT
    By sophister in forum Qt Programming
    Replies: 5
    Last Post: 25th April 2009, 08:03
  3. Signal and slot
    By seldeepchan in forum Qt Programming
    Replies: 6
    Last Post: 12th March 2008, 10:05
  4. Replies: 1
    Last Post: 8th November 2007, 17:11
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.