Hi All,


I am attempting to write a function that pops a dialog. My ultimate goal is to call this function via signal/slot. But for now I am just trying to validate that the function will pop a dialog.

I designed a toy dialog for testing purposes. Here is the code for the dialog:

Qt Code:
  1. class ShareDialog : public QDialog
  2. {
  3. //Q_OBJECT
  4. public:
  5. ShareDialog(QWidget *parent=0);
  6.  
  7. private:
  8. QPushButton *exitButton;
  9. QLabel *label;
  10. };
  11.  
  12. ShareDialog::ShareDialog(QWidget *parent) : QDialog(parent)
  13. {
  14. label = new QLabel("Hello! This this is the 'Select' dialog!");
  15. exitButton = new QPushButton("Bugout!");
  16.  
  17. connect(exitButton, SIGNAL(clicked()), this, SLOT(close()) );
  18.  
  19. QHBoxLayout * theLayout = new QHBoxLayout;
  20. theLayout->addWidget(label);
  21. theLayout->addWidget(exitButton);
  22. setLayout(theLayout);
  23. }
To copy to clipboard, switch view to plain text mode 

The dialog works as expected if I invoke it from main():

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QApplication app(argc, argv);
  4.  
  5. ShareDialog * shareDialog = new ShareDialog;
  6. shareDialog->show();
  7.  
  8. HistoryWindow w;
  9.  
  10. w.show();
  11.  
  12. return app.exec();
  13. }
To copy to clipboard, switch view to plain text mode 

When I invoke show() from main it works just as I expected. But, when I attempt to the same thing from a different function it crashes the app:

Qt Code:
  1. void HistoryWindow::PopShareDialog()
  2. {
  3. if (!dlg)
  4. {
  5. dlg = new ShareDialog(this);
  6. }
  7.  
  8. Q_ASSERT( dlg != NULL);
  9. dlg->show(); // app crashes if this executes
  10. //shareDialog->raise();
  11. //shareDialog->activateWindow();
  12. }
  13.  
  14. HistoryWindow::HistoryWindow(QWidget *parent) : QMainWindow(parent),
  15. ui(new Ui::HistoryWindow)
  16. {
  17. ui->setupUi(this);
  18. createModelAndView();
  19.  
  20. PopShareDialog(); // invoking the dialog from here doesn't work
  21. }
To copy to clipboard, switch view to plain text mode 

I do not understand why invoking show() from within PopShareDialog() causes a crash. Does anyone have a clue?