Results 1 to 4 of 4

Thread: Need concurrency advice with callback function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2012
    Posts
    25
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    7

    Default Need concurrency advice with callback function

    (PyQt 4.8, Python 2.7)
    After reading through the following I'm still left a bit puzzled as to which approach to attempt to utilize for my situation. Any advice would be appreciated.
    Keeping_the_GUI_Responsive

    I have a module, flp.so library to which I have no control over. It takes a function as a constructor argument, and performs a complex/long calculation when invoking the run() method. Here I subclassed QThread, and invoke flp.run inside the thread's run method. In turn the flp module will invoke the callback method, which emits a signal. I catch the signal back in my main thread, and update a model for a QTreeView and update a QProgressBar.
    Qt Code:
    1. def my_runner(QThread):
    2. def __init__(self,callback=None):
    3. self.callback = callback
    4.  
    5. def callback(self):
    6. # f_runner.f_output is array that is appended every iteration of f_runner.run()
    7. emit(SIGNAL('update_main'),self.f_runner.f_output.pop())
    8.  
    9. def run(self):
    10. import flp
    11. self.f_runner = flp.f_runner(callback=self.callback)
    12. self.f_runner.run()
    To copy to clipboard, switch view to plain text mode 

    However, the GUI is not very responsive, as the signals are probably stacking up and the events can't be processed fast enough. I try to avoid invoking QApplication.processEvents(), but tried it here and very bad things happen.

    I have been rethinking this design but have gotten stuck. Eventually I would like the main thread GUI to be responsive while this thread is working and updating the progress bar and table view in the main.

    TYVM for reading.
    Last edited by BreakBad; 29th January 2013 at 19:18.

Similar Threads

  1. using function pointers and callback functions
    By ehnuh in forum General Programming
    Replies: 2
    Last Post: 5th November 2012, 12:00
  2. Qt classes in a callback function
    By Luc4 in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2010, 14:47
  3. Interoperability of C Callback function and Qt
    By Vogel Ubrhar in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2010, 17:02
  4. structs, pointer, static callback function
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 20th June 2008, 13:53
  5. how to define the callback function in QThread?
    By cxl2253 in forum Qt Programming
    Replies: 6
    Last Post: 30th March 2007, 11:59

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
  •  
Qt is a trademark of The Qt Company.