Results 1 to 18 of 18

Thread: GUI Freezes unless there's incoming data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy GUI Freezes unless there's incoming data

    Hi all

    I'm programming a basic IRC client, and have an IRC api/library, the Qt Designer generated interface file, and a separate module in the middle to link the two into some kind of functionality.

    In the IRC library, I have a member function that checks a socket I've set up for any incoming data:

    Qt Code:
    1. def recvLoop(self):
    2. try:
    3. data = self.irc.recv(4096)
    4. if data.find('PING') != -1:
    5. self.irc.send('PONG ' + data.split() [1] + '\r\n')
    6. if len(data) > 0:
    7. incomingBuffer.put(data)
    8. #print data
    9. #time.sleep(1)
    10. except:
    11. print 'Error: Possible interupt.'
    To copy to clipboard, switch view to plain text mode 
    Then in the main module (mainwindow.py) that uses the IRC library, I have the following:

    Qt Code:
    1. @pyqtSignature("")
    2. def on_connectButton_clicked(self):
    3.  
    4. self.displayBrowser.append('Connecting...')
    5. client = crisp_irc.IRC()
    6. client.newConnection('irc.oftc.net', 6667, 'crispycream', 'crisp', 'crisp')
    7. client.join('#crasp')
    8. client.channelSend('#crasp', 'blah')
    9. client.set_recv_function(crisp_irc.my_receive)
    10.  
    11. while 1:
    12. client.recvLoop()
    13. QApplication.processEvents()
    14. if crisp_irc.incomingBuffer.qsize() > 0:
    15. print crisp_irc.incomingBuffer.qsize()
    16. item = crisp_irc.incomingBuffer.get()
    17. #print item
    18. self.displayBrowser.append(item)
    19. crisp_irc.incomingBuffer.task_done()
    20. QApplication.processEvents()
    21.  
    22. ...
    23.  
    24. if __name__ == "__main__":
    25. import sys
    26.  
    27. app = QApplication(sys.argv)
    28. form = CrispIRCMainWindow()
    29.  
    30. form.show()
    31. app.exec_()
    To copy to clipboard, switch view to plain text mode 
    So if there's data, the IRC lib puts it into a (global - for now) buffer, and the mainwindow.py reads from that buffer to see if its empty or not. If it isnt, it appends it to the main display window.

    The QApplication.processEvents() calls have solved half of my problem. The remaining problem is that the GUI freezes UNLESS the buffer is not empty, at which point it updates everything to how it should be, then goes straight back to being frozen/in a crash like state. The client does stay connected during this, and does receive messages etc, hence it updates when there's something to show.

    How do I get rid of this behaviour (I've tried sleeping for a second etc, no dice)? Is there a better way to pass data along to the GUI from the library I've made? Many many thanks in advance!!

    EDIT: Maybe there's a way to detect when there's data to be received, and only execute the function when there is something to be sent down the socket? Kind of data drive rather than a constant infinite loop that keep polling things, which is possibly the source of my problem?
    Last edited by crisp; 25th January 2009 at 22:10.

Similar Threads

  1. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  2. Replies: 7
    Last Post: 29th August 2008, 10:24
  3. Replies: 4
    Last Post: 19th October 2007, 19:47
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.