One problem with your code, which in this case probably works but simply by accident, is that you are creating your text item on the stack. It works here because the main() method doesn't exit until the app does, so the text item stays in scope. However, if you do this same thing anywhere else in a method that returns, your text item will be destroyed (and thus removed from the scene) as soon as the method exits. That's a bug waiting to happen.
On the other hand, you allocate the scene on the heap, the pixmap item on the heap, but the pixmap itself on the stack. It is very inconsistent. The first fix I would make is to allocate everything on the heap using new (except maybe the pixmap itself, since the pixmap item makes a copy) and see if there's a change in behavior.
You also haven't given any graphics item a position, nor have you set a size for the scene or view. So who knows if this reliance on default behavior is what is causing the problem?
Bookmarks