Hi, this is just a general question, I've been wondering, is it possible if I call a method from main which displays a widget.

Recently, I tried writing a simple code for quick coding. I wrote a main method, and decided to call another method to draw widgets. Problem is, the widget will not
stay and display it, even though I directed the widget to be shown (using widget->show()) in the calling method.

My guess is that main method is the only one that called QApplication and asked it to perform event exec(), waiting for exit signal or something, while the calling method is only executed once and on-the-go (no wait flag or anything). Can anyone explaina bit further on this?

Also, if I decided to code from main, and then calling in methods that draws widgets, how can I make them stay displayed? Is there any function to keep the widget being displayed?

Here is a sample code snippet:

Qt Code:
  1. #include <QApplication>
  2. #include <QMainWindow>
  3. #include <QPushButton>
  4.  
  5.  
  6. void newWindow()
  7. {
  8. main.show();
  9. }
  10.  
  11.  
  12. int main(int argc, char*argv[])
  13. {
  14. QApplication app(argc,argv);
  15. return app.exec();
  16. }
To copy to clipboard, switch view to plain text mode 

The problem with this code is that, the widget won't display at all, or more accurately, it'll display the widget when entering method newWindow, but when returning to main, it'll be destroyed.

Is there some way to make the QMainWindow still being displayed, even after returning to main method?