Thank you for your ideas.

1) & 4) The reason I emit a signal on accept() is because I need to get the index of the spinbox that was selected. If there's a better way to do this, let me know!

2) Why would this be a bad thing? I need to free the memory before the dialog ceases to exist, right?

3) Yes, that was just a mistake.

Revised code that still produces a seg fault:
Qt Code:
  1. #ifndef GENERATENEWDIALOG_H
  2. #define GENERATENEWDIALOG_H
  3.  
  4. #include <QDialog>
  5. #include <QSpinBox>
  6. #include <QDialogButtonBox>
  7. #include <QVBoxLayout>
  8. #include <QHBoxLayout>
  9. #include <QLabel>
  10. #include <QSpinBox>
  11. #include <QPushButton>
  12. #include <QDebug>
  13. class GenerateNewDialog : public QDialog
  14. {
  15. Q_OBJECT
  16. private:
  17. void setupInterface();
  18. void setupActions();
  19. QVBoxLayout * m_mainLayout;
  20. QHBoxLayout * m_firstSetting;
  21. QLabel * m_label1;
  22. QSpinBox * m_difficultyPicker;
  23. QPushButton * m_cancel, * m_start;
  24. QDialogButtonBox *buttonBox;
  25. int m_difficulty;
  26. public:
  27. explicit GenerateNewDialog(QWidget *parent = 0);
  28. virtual ~GenerateNewDialog();
  29. signals:
  30. void difficultySelected(int difficulty);
  31. private slots:
  32. virtual void accept();
  33. virtual void reject();
  34. public slots:
  35.  
  36. };
  37.  
  38. #endif // GENERATENEWDIALOG_H
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #include "generatenewdialog.h"
  2.  
  3. GenerateNewDialog::GenerateNewDialog(QWidget *parent) :
  4. QDialog(parent, Qt::Sheet)
  5. {
  6. setupInterface();
  7. setupActions();
  8. }
  9. //----------------------------------------------------------------------------
  10. // Constructor & destructor.
  11.  
  12. GenerateNewDialog::~GenerateNewDialog(void) {
  13. // Is automatically deleted, because it's a child of of the main widget.
  14. //delete m_mainLayout;
  15. delete m_firstSetting;
  16. delete m_label1;
  17. delete m_difficultyPicker;
  18. delete m_cancel;
  19. delete m_start;
  20. }
  21.  
  22.  
  23. //----------------------------------------------------------------------------
  24. // Private slots.
  25.  
  26. /**
  27.  * The dialog was accepted. Emit the newGame() signal.
  28.  */
  29. void GenerateNewDialog::accept(void) {
  30. m_difficulty = m_difficultyPicker->value();
  31.  
  32. emit difficultySelected(m_difficulty);
  33. QDialog::accept();
  34. }
  35.  
  36.  
  37. //----------------------------------------------------------------------------
  38. // Private methods.
  39.  
  40. /**
  41.  * Create the UI.
  42.  */
  43. void GenerateNewDialog::setupInterface(void) {
  44. setContextMenuPolicy(Qt::NoContextMenu);
  45. setModal(true);
  46.  
  47. // Configure layouts.
  48. m_mainLayout = new QVBoxLayout(this);
  49. m_firstSetting = new QHBoxLayout();
  50. m_mainLayout->addLayout(m_firstSetting);
  51.  
  52. // Set up the buttons.
  53. this->buttonBox = new QDialogButtonBox(this);
  54. this->buttonBox->setOrientation(Qt::Horizontal);
  55. m_cancel = new QPushButton(tr("&Cancel"));
  56. this->buttonBox->addButton(m_cancel, QDialogButtonBox::RejectRole);
  57. m_start = new QPushButton(tr("&Start!"));
  58. m_start->setDefault(true);
  59. this->buttonBox->addButton(m_start, QDialogButtonBox::AcceptRole);
  60. m_mainLayout->addWidget(buttonBox);
  61.  
  62. // Difficulty label.
  63. m_label1 = new QLabel(this);
  64. m_label1->setText(tr("Difficulty level"));
  65. m_firstSetting->addWidget(m_label1);
  66. m_firstSetting->setAlignment(m_label1, Qt::AlignLeft);
  67.  
  68. // Difficulty spinbox.
  69. m_difficultyPicker = new QSpinBox(this);
  70. m_difficultyPicker->setMinimum(1);
  71. m_difficultyPicker->setMaximum(5);
  72. m_difficultyPicker->setSingleStep(1);
  73. m_difficultyPicker->setValue(1);
  74. m_firstSetting->addWidget(m_difficultyPicker);
  75. m_firstSetting->setAlignment(m_difficultyPicker, Qt::AlignRight);
  76. }
  77. void GenerateNewDialog::setupActions(){
  78. // Connect the signals from the buttonbox to the NewGameDialog.
  79. connect(this->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  80. connect(this->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
  81. }
  82.  
  83. void GenerateNewDialog::reject(){
  84. qDebug() << "GenerateNewDialog received reject signal.";
  85. QDialog::reject();
  86. close();
  87. }
To copy to clipboard, switch view to plain text mode