It has been a while since I tried programming using QT so I might be doing something very newbish.

Here is the situation:
--Ubuntu 8.10
--QT 4.5 binary install that includes Qt Creator 1.0

Application:
--MainWindow with two dialog boxes

I autogenerate the dialog code using Qt Creator so I have two classes that are called Ui_Dialog and Ui_Dialog2.

When I try to initialize them in the MainWindow constructor the entire application seg faults when it is run.

Here is the code:

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QtGui/QMainWindow>
  5. #include <QDialog>
  6.  
  7. namespace Ui
  8. {
  9. class Dialog;
  10. class Dialog2;
  11. class MainWindowClass;
  12. }
  13.  
  14. class MainWindow : public QMainWindow
  15. {
  16. Q_OBJECT
  17.  
  18. public:
  19. MainWindow(QWidget *parent = 0);
  20. ~MainWindow();
  21.  
  22. private:
  23. QDialog dOne;
  24. QDialog dTwo;
  25.  
  26. Ui::MainWindowClass *ui;
  27. Ui::Dialog *p_dOne;
  28. Ui::Dialog2 *p_dTwo;
  29. };
  30.  
  31. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_dialog.h"
  3. #include "ui_dialog2.h"
  4. #include "ui_mainwindow.h"
  5.  
  6. MainWindow::MainWindow(QWidget *parent)
  7. : QMainWindow(parent), ui(new Ui::MainWindowClass)
  8. {
  9. ui->setupUi(this);
  10. p_dOne->setupUi(&dOne);
  11. p_dTwo->setupUi(&dTwo);
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16. delete ui;
  17. }
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. /********************************************************************************
  2. ** Form generated from reading ui file 'dialog.ui'
  3. **
  4. ** Created: Sat Mar 21 22:13:51 2009
  5. ** by: Qt User Interface Compiler version 4.5.0
  6. **
  7. ** WARNING! All changes made in this file will be lost when recompiling ui file!
  8. ********************************************************************************/
  9.  
  10. #ifndef UI_DIALOG_H
  11. #define UI_DIALOG_H
  12.  
  13. #include <QtCore/QVariant>
  14. #include <QtGui/QAction>
  15. #include <QtGui/QApplication>
  16. #include <QtGui/QButtonGroup>
  17. #include <QtGui/QDialog>
  18. #include <QtGui/QDialogButtonBox>
  19. #include <QtGui/QGridLayout>
  20. #include <QtGui/QHeaderView>
  21. #include <QtGui/QLabel>
  22.  
  23. QT_BEGIN_NAMESPACE
  24.  
  25. class Ui_Dialog
  26. {
  27. public:
  28. QGridLayout *gridLayout;
  29. QLabel *label;
  30. QDialogButtonBox *buttonBox;
  31.  
  32. void setupUi(QDialog *Dialog)
  33. {
  34. if (Dialog->objectName().isEmpty())
  35. Dialog->setObjectName(QString::fromUtf8("Dialog"));
  36. Dialog->resize(400, 100);
  37. gridLayout = new QGridLayout(Dialog);
  38. gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
  39. label = new QLabel(Dialog);
  40. label->setObjectName(QString::fromUtf8("label"));
  41.  
  42. gridLayout->addWidget(label, 0, 0, 1, 1);
  43.  
  44. buttonBox = new QDialogButtonBox(Dialog);
  45. buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
  46. buttonBox->setOrientation(Qt::Horizontal);
  47. buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
  48.  
  49. gridLayout->addWidget(buttonBox, 1, 0, 1, 1);
  50.  
  51.  
  52. retranslateUi(Dialog);
  53. QObject::connect(buttonBox, SIGNAL(accepted()), Dialog, SLOT(accept()));
  54. QObject::connect(buttonBox, SIGNAL(rejected()), Dialog, SLOT(reject()));
  55.  
  56. QMetaObject::connectSlotsByName(Dialog);
  57. } // setupUi
  58.  
  59. void retranslateUi(QDialog *Dialog)
  60. {
  61. Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
  62. label->setText(QApplication::translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
  63. "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
  64. "p, li { white-space: pre-wrap; }\n"
  65. "</style></head><body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
  66. "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Dialog One</p></body></html>", 0, QApplication::UnicodeUTF8));
  67. Q_UNUSED(Dialog);
  68. } // retranslateUi
  69.  
  70. };
  71.  
  72. namespace Ui {
  73. class Dialog: public Ui_Dialog {};
  74. } // namespace Ui
  75.  
  76. QT_END_NAMESPACE
  77.  
  78. #endif // UI_DIALOG_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. /********************************************************************************
  2. ** Form generated from reading ui file 'dialog2.ui'
  3. **
  4. ** Created: Sat Mar 21 22:15:00 2009
  5. ** by: Qt User Interface Compiler version 4.5.0
  6. **
  7. ** WARNING! All changes made in this file will be lost when recompiling ui file!
  8. ********************************************************************************/
  9.  
  10. #ifndef UI_DIALOG2_H
  11. #define UI_DIALOG2_H
  12.  
  13. #include <QtCore/QVariant>
  14. #include <QtGui/QAction>
  15. #include <QtGui/QApplication>
  16. #include <QtGui/QButtonGroup>
  17. #include <QtGui/QDialog>
  18. #include <QtGui/QDialogButtonBox>
  19. #include <QtGui/QGridLayout>
  20. #include <QtGui/QHeaderView>
  21. #include <QtGui/QLabel>
  22.  
  23. QT_BEGIN_NAMESPACE
  24.  
  25. class Ui_Dialog2
  26. {
  27. public:
  28. QGridLayout *gridLayout;
  29. QLabel *label;
  30. QDialogButtonBox *buttonBox;
  31.  
  32. void setupUi(QDialog *Dialog2)
  33. {
  34. if (Dialog2->objectName().isEmpty())
  35. Dialog2->setObjectName(QString::fromUtf8("Dialog2"));
  36. Dialog2->resize(400, 100);
  37. gridLayout = new QGridLayout(Dialog2);
  38. gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
  39. label = new QLabel(Dialog2);
  40. label->setObjectName(QString::fromUtf8("label"));
  41.  
  42. gridLayout->addWidget(label, 0, 0, 1, 1);
  43.  
  44. buttonBox = new QDialogButtonBox(Dialog2);
  45. buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
  46. buttonBox->setOrientation(Qt::Horizontal);
  47. buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
  48.  
  49. gridLayout->addWidget(buttonBox, 1, 0, 1, 1);
  50.  
  51.  
  52. retranslateUi(Dialog2);
  53. QObject::connect(buttonBox, SIGNAL(accepted()), Dialog2, SLOT(accept()));
  54. QObject::connect(buttonBox, SIGNAL(rejected()), Dialog2, SLOT(reject()));
  55.  
  56. QMetaObject::connectSlotsByName(Dialog2);
  57. } // setupUi
  58.  
  59. void retranslateUi(QDialog *Dialog2)
  60. {
  61. Dialog2->setWindowTitle(QApplication::translate("Dialog2", "Dialog", 0, QApplication::UnicodeUTF8));
  62. label->setText(QApplication::translate("Dialog2", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
  63. "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
  64. "p, li { white-space: pre-wrap; }\n"
  65. "</style></head><body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
  66. "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Dialog Two</p></body></html>", 0, QApplication::UnicodeUTF8));
  67. Q_UNUSED(Dialog2);
  68. } // retranslateUi
  69.  
  70. };
  71.  
  72. namespace Ui {
  73. class Dialog2: public Ui_Dialog2 {};
  74. } // namespace Ui
  75.  
  76. QT_END_NAMESPACE
  77.  
  78. #endif // UI_DIALOG2_H
To copy to clipboard, switch view to plain text mode 

The last two are automatically generated. I cannot figure out why initializing them both in the MainWindow constructor would cause a seg fault!!!