Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:14:21+00:00 2026-06-11T14:14:21+00:00

Following code should create the QGraphicsView widget which owns one QGraphicsScene having text inside

  • 0

Following code should create the QGraphicsView widget which owns one QGraphicsScene having text inside of it:

#!/usr/bin/python

import sys
from PyQt4.QtGui import *


if __name__ == '__main__':
  app = QApplication(sys.argv)

  view = QGraphicsView()  
  scene = QGraphicsScene()

  scene.addText("Hello!")

  view.setScene(scene)
  view.show();

  sys.exit(app.exec_())

This opens the window, puts the text there, but after I close window – python dumps core and several issues are printed out:

(python:5387): Gtk-CRITICAL **: IA__gtk_container_add: assertion `GTK_IS_CONTAINER (container)' failed

(python:5387): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
...clip...
... above message is shown many, many times ...
...clip...
(python:5387): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
Segmentation fault (core dumped)

Versions:
python2.7 2.7.3-0ubuntu3.1
python-qt4 4.9.1-2ubuntu1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:14:22+00:00Added an answer on June 11, 2026 at 2:14 pm

    This is probably neither a PyQt bug, nor wrongly behaving code.

    When python goes through its shutdown process, the order in which objects get deleted can be unpredictable. Occasionally, this may cause somewhat baffling error messages to appear.

    Your script runs fine on my (non-Ubuntu) Linux machine – but when I close the window, I get this output:

    $ python2 test.py 
    QPixmap: Must construct a QApplication before a QPaintDevice
    Aborted
    

    Which, taken at face value, seems to make no sense at all…

    However, it’s usually pretty easy to get rid of such error messages by forcing the objects to be deleted in a different order.

    One (slightly strange) way to do this is to just rename some of the objects. So for me, the error messages disappear if I simply change view to _view.

    However, a perhaps better alternative is to make sure that certain key objects are connected together in a parent/child hierarchy:

        view = QGraphicsView()  
        scene = QGraphicsScene(view)
    

    The reason for doing this, is that when deleteing an object, Qt will also automatically delete all of its descendant QObject nodes. This can help to ensure that the C++ side of PyQt objects is cleaned up before the python side (which is really at the core of what causes these kinds of problems).

    Another possibility is to keep a global reference to the QApplication, and put everything else in a main function:

    import sys
    from PyQt4.QtGui import *
    
    def main():
        view = QGraphicsView()
        scene = QGraphicsScene()
        scene.addText("Hello!")
        view.setScene(scene)
        view.show()
        return qApp.exec_()
    
    if __name__ == '__main__':
    
        app = QApplication(sys.argv)
        sys.exit(main())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which should be getting the text from a span
I have the following code, that in my head should create a new row
The following code should display the id out of the JSON-object, which I got
hi i have write following code which prints elements in sorted order only one
Helo, i have the following code which should filter entities. Half of the code
The following code should create two Random objects with identical seeds: System.out.println(System time before:
The following code seems reasonable to me. It should create the object and then
The following code should show a certain track in iTunes: NSString* iTunesPath = [[NSWorkspace
The following code should pop up an alert box whenever I select a file
The following code should exhibit intended functionality: <head> <style> a:active { color:teal; } a:hover

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.