Great, everything compiles but when I execute, and try the reset button, it kills the application. The error I get is:
Segmentation fault (core dumped)
This is a simple test, here is my code:
window.h:
#ifndef WINDOW_H
#define WINDOW_H
#include <QDialog>
{
Q_OBJECT
public:
private slots:
void reset();
private:
};
#endif
#ifndef WINDOW_H
#define WINDOW_H
#include <QDialog>
class QLabel;
class QCheckBox;
class QPushButton;
class QButtonGroup;
class Window : public QDialog
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
private slots:
void reset();
private:
QPushButton *createButton(const QString &text, const char * member);
QLabel *label;
QButtonGroup *buttonGroup;
QCheckBox *checkBox_1;
QCheckBox *checkBox_2;
QCheckBox *checkBox_3;
QCheckBox *checkBox_4;
QPushButton *resetButton;
};
#endif
To copy to clipboard, switch view to plain text mode
window.cpp:
#include <QtGui>
#include "window.h"
{
resetButton = createButton(tr("Reset"), SLOT(reset()));
buttonGroup->setExclusive(0);
buttonGroup->addButton(checkBox_1, 1);
buttonGroup->addButton(checkBox_2, 2);
buttonGroup->addButton(checkBox_3, 3);
buttonGroup->addButton(checkBox_4, 4);
layout->addWidget(checkBox_1);
layout->addWidget(checkBox_2);
layout->addWidget(checkBox_3);
layout->addWidget(checkBox_4);
layout->addWidget(resetButton);
setLayout(layout);
}
{
connect(button, SIGNAL(clicked()), this, member);
return button;
}
void Window::reset()
{
for (int i=1;i < 5; i++)
buttonGroup->button(i)->setChecked(0);
}
#include <QtGui>
#include "window.h"
Window::Window(QWidget *parent)
: QDialog(parent)
{
resetButton = createButton(tr("Reset"), SLOT(reset()));
QCheckBox *checkBox_1 = new QCheckBox(tr("Backgrounds..."));
QCheckBox *checkBox_2 = new QCheckBox(tr("Cell Phones..."));
QCheckBox *checkBox_3 = new QCheckBox(tr("Automotive..."));
QCheckBox *checkBox_4 = new QCheckBox(tr("Computers..."));
QButtonGroup* buttonGroup = new QButtonGroup(this);
buttonGroup->setExclusive(0);
buttonGroup->addButton(checkBox_1, 1);
buttonGroup->addButton(checkBox_2, 2);
buttonGroup->addButton(checkBox_3, 3);
buttonGroup->addButton(checkBox_4, 4);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(checkBox_1);
layout->addWidget(checkBox_2);
layout->addWidget(checkBox_3);
layout->addWidget(checkBox_4);
layout->addWidget(resetButton);
setLayout(layout);
}
QPushButton *Window::createButton(const QString &text, const char *member)
{
QPushButton *button = new QPushButton(text);
connect(button, SIGNAL(clicked()), this, member);
return button;
}
void Window::reset()
{
for (int i=1;i < 5; i++)
buttonGroup->button(i)->setChecked(0);
}
To copy to clipboard, switch view to plain text mode
Finally, a simple main.cpp:
#include <QApplication>
#include "window.h"
int main(int argc, char * argv[])
{
Window window;
window.show();
return app.exec();
}
#include <QApplication>
#include "window.h"
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Any suggestions?
Thank you very much!
Bookmarks