Results 1 to 1 of 1

Thread: [PyQt4] Crash when writing to QTextEdit in a thread

  1. #1
    Join Date
    May 2009
    Posts
    3
    Qt products
    Platforms
    Unix/X11

    Default [PyQt4] Crash when writing to QTextEdit in a thread

    Running PyQT4 on Kubuntu 7.x

    I'm getting segfaults when running operations in a spawned thread. I create a dialog with a QTextEdit in it and pass a reference to the dialog into the thread. The thread then does some work while writing information to the QTextEdit. The segfaults don't seem to happen if I don't create the window, or if I create the window and don't write to it.

    I've tried this with both python threads and QThread with the same results. Funny thing is, the "DoUtilityOperation" function usually completes all its tasks before the crash happens.

    Update: I actually do get problems before the tasks are completed. One of these two errors appears and hangs the dialog:
    QTreeView::rowsInserted internal representation of the model has been corrupted, resetting.
    *** glibc detected *** python: realloc(): invalid next size: 0x0000000000fe1430 ***

    Am I simply going about this the wrong way? Is this way inherently unstable? Is there a smarter way to do this?

    Thanks for any help!

    A simplified version of my code follows:

    Qt Code:
    1. #MyOperation button clicked
    2. @pyqtSignature("")
    3. def on_button_MyOperation_clicked(self):
    4. #pass to the operation handler
    5. self.utilityButtonClicked('MyOperation')
    6.  
    7.  
    8. def utilityButtonClicked(self, operation):
    9. #get selected items
    10. selectedItems = self.treeWidget_Files.selectedItems()
    11. if len(selectedItems) > 0:
    12. #progressViewer is a dialog that contains a QTextEdit widget
    13. window = progressViewer.progressViewer(self)
    14. window.setVisible(True)
    15. window.show()
    16. utilityThread = None
    17. #create the thread to do the utility operation
    18. utilityThread = threading.Thread( None, self.DoUtilityOperation, None, ( operation, selectedItems, window ) )
    19. utilityThread.start()
    20. self.threads.append( utilityThread ) #store the thread
    21.  
    22.  
    23.  
    24. def DoUtilityOperation( self, operation, selectedItems, window ):
    25. for item in selectedItems: #run the operation on each item
    26. self.DoUtilityOperationOnItem( operation, item, window )
    27.  
    28.  
    29.  
    30. def DoUtilityOperationOnItem( self, operation, item, window ):
    31. #do some stuff
    32.  
    33. #output text using this code several times
    34. window.textEdit_ProgressDisplay.append( 'some text' )
    35. window.textEdit_ProgressDisplay.moveCursor( QTextCursor.End )
    36.  
    37. #do some other stuff
    To copy to clipboard, switch view to plain text mode 
    Last edited by robtheg; 13th May 2009 at 07:46. Reason: updated contents

Similar Threads

  1. accesing QTextEdit from thread
    By msmihai in forum Qt Programming
    Replies: 1
    Last Post: 8th December 2008, 11:40
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Replies: 10
    Last Post: 20th March 2007, 22:19

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.