tags:

views:

40

answers:

3

Hi all,

I cannot open a new window in QT. I new in QT so I think I am missing something. I only write the code below and settings windows just shows itself and closes. I have commented out destructor but still problem persists.

SettingsWindow s;
s.show();

What do I do wrong ? By the way I cannot either debug it, debuger does not stop when it reaches to the first line for example.

Thanks

+3  A: 

This can't possibly be the only code you wrote.

However, judging from your description the first thing that comes to mind is probably a missing call to QApplication::exec(). Somewhere in the code you haven't shown here there's an instance of QApplication, probably named app. After calling show on your window, make sure there's a call to exec.

Idan K
I have changed the instructions like this; SettingsWindow *s = new SettingsWindow(); s->show(); and it runs. But I still dont know what is the difference ?
Harun Baris Bulut
+1  A: 

See this basic tutorial on how to set up basic widgets and a working application.

shoosh
+2  A: 

Since you are using a non-pointer var, your window is destroy when it go our of scope (at the end of the function). If you use a pointer when exiting the function the memory is not deleted so you Windows will still be shown. But you will not be able to clean memory when closing the window if you can't anymore access to your pointer.

Maybe you need to create your window as member of the calling class in order to be able to destroy the window AND clean memory once you don't need anymore to display it (for example in the calling class destructor).

Patrice Bernassola