Hi,
I've been reading through the GUI programming with Qt4 and really need help understanding the central widget. Here's my code:
#include <QMainWindow>
#include <QtGui>
{
public:
MainWindow(); // Constructor
};
MainWindow::MainWindow()
{
mainLayout->addWidget(spinBox);
this->centralWidget()->setLayout(mainLayout);
}
int main(int argc, char *argv[])
{
QApplication app
(argc, argv
);
// Create application. Arguments as parameters MainWindow *mainWindow = new MainWindow; // Create the application window
mainWindow->show(); // Show the application window
return app.exec();
}
#include <QMainWindow>
#include <QtGui>
class MainWindow : public QMainWindow
{
public:
MainWindow(); // Constructor
};
MainWindow::MainWindow()
{
QSpinBox *spinBox = new QSpinBox;
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(spinBox);
this->centralWidget()->setLayout(mainLayout);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv); // Create application. Arguments as parameters
MainWindow *mainWindow = new MainWindow; // Create the application window
mainWindow->show(); // Show the application window
return app.exec();
}
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
Bookmarks