But that code differs from what you posted in #1. So which one is correct, which class is the main window and which is not?

Anyway, your vanishing window problem comes from the already mentioned twice problem that you are allocating the window on the stack that unwinds immediately after the function completes its course.