Hi,

I've been reading through the GUI programming with Qt4 and really need help understanding the central widget. Here's my code:


Qt Code:
  1. #include <QMainWindow>
  2. #include <QtGui>
  3.  
  4. class MainWindow : public QMainWindow
  5. {
  6. public:
  7. MainWindow(); // Constructor
  8. };
  9.  
  10.  
  11. MainWindow::MainWindow()
  12. {
  13. QSpinBox *spinBox = new QSpinBox;
  14. QVBoxLayout *mainLayout = new QVBoxLayout();
  15. mainLayout->addWidget(spinBox);
  16. this->centralWidget()->setLayout(mainLayout);
  17. }
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21. QApplication app(argc, argv); // Create application. Arguments as parameters
  22. MainWindow *mainWindow = new MainWindow; // Create the application window
  23. mainWindow->show(); // Show the application window
  24. return app.exec();
  25. }
To copy to clipboard, switch view to plain text mode 

This is my program simplified, all in one file. Although it compiles just fine, the program will crash upon being run.

I really have been trying to figure out how to do this correctly and would really appreciate if someone could point in the right direction!

Thanks