Results 1 to 3 of 3

Thread: Segfault trying to access gui (single thread)

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Segfault trying to access gui (single thread)

    I have a problem trying to hide/show my widget.
    This is an example of what I have:

    main.py
    Qt Code:
    1. class Main(QMainWindow):
    2. def __init__(self):
    3. QMainWindow.__init__(self, parent=None)
    4. self.gui = Gui()
    5.  
    6. def onMyCustomEvent(self):
    7. self.gui.showOrHide() #<---- SEGFAULT
    8.  
    9. app = QtGui.QApplication(sys.argv)
    10. window = Main()
    11. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    gui.py
    Qt Code:
    1. class Gui(QWidget):
    2. def __init__(self):
    3. QWidget.__init__(self, parent=None)
    4. #set size of widget
    5. #set title
    6. #.....
    7. #.....
    8.  
    9. def showOrHide(self):
    10. if self.isVisible():
    11. self.setVisible(False)
    12. else:
    13. self.setVisible(True)
    To copy to clipboard, switch view to plain text mode 

    So, this is the code, and when I try to show or hide the gui, I get a SEGFAULT or a message saying "QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread". The SEGFAULT and the message appear randomly.
    I have searched and the message means that I must use processEvent, postEvent and so on because I'm trying to access a gui from another thread, but I'm _not_! I don't use threads in my app, so I'm a little confused.
    Why could be happening?

    Thanks

  2. #2
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Segfault trying to access gui (single thread)

    I have been playing with this all day and I found that if I do "print self.width()" in the "showOrHide" method, it will print the width of the widget and it _won't_ segfault. In fact, I can access every method from my qwidget that will return a value, and I can print it. But I can't set any value to my widget because it will segfault.
    Any ideas? Any clues of why could this be happening?

  3. #3
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Segfault trying to access gui (single thread)

    Found a solution. In "onMyCustomEvent()" instead of doing "self.gui.showOrHide()" I do "self.emit(QtCore.SIGNAL("showOrHideEvent()")) " and in main I do "self.connect(self, QtCore.SIGNAL("showOrHideEvent()"), self.console.showOrHide)" so I can catch it.
    Thanks to everyone for reading this topic.

Similar Threads

  1. segfault while trying to access QList
    By Raven24 in forum General Programming
    Replies: 1
    Last Post: 3rd March 2010, 06:53
  2. QTcpServer - Multi thread or single?
    By December in forum Qt Programming
    Replies: 3
    Last Post: 8th February 2008, 10:31
  3. Segfault
    By Dumbledore in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 07:31
  4. Replies: 11
    Last Post: 7th July 2006, 13:09
  5. segfault
    By conexion2000 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2006, 12:34

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.