Hi everyone, I have just downloaded QT 5.4.1 for a couple of days. Because there is no book for Qt 5, I use the book named "C++ GUI Programming with Qt 4". I'm learning about QDialog and Qt Designer, and I copied the source code from that book to run on my Qt. However, it didn't work but announced "The inferior stopped because it triggered an exception.". I don't know why. Here are he source code:
The header:
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include <QDialog>
#include "ui_gotocelldialog.h"
namespace Ui
{
class GoToCellDialog;
}
class GoToCellDialog
: public QDialog,
public Ui
::GoToCellDialog{
Q_OBJECT
public:
explicit GoToCellDialog
(QWidget *parent
= 0);
~GoToCellDialog();
private slots:
void on_lineEdit_textChanged();
private:
Ui::GoToCellDialog *ui;
};
#endif // GOTOCELLDIALOG_H
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include <QDialog>
#include "ui_gotocelldialog.h"
namespace Ui
{
class GoToCellDialog;
}
class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
{
Q_OBJECT
public:
explicit GoToCellDialog(QWidget *parent = 0);
~GoToCellDialog();
private slots:
void on_lineEdit_textChanged();
private:
Ui::GoToCellDialog *ui;
};
#endif // GOTOCELLDIALOG_H
To copy to clipboard, switch view to plain text mode
The implementation of the class:
#include "gotocelldialog.h"
GoToCellDialog
::GoToCellDialog(QWidget *parent
) ui(new Ui::GoToCellDialog)
{
ui->setupUi(this);
QRegExp regExp
("[A-Za-z][1-9][0-9]{0,2}");
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
}
GoToCellDialog::~GoToCellDialog()
{
delete ui;
}
void GoToCellDialog::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
#include "gotocelldialog.h"
GoToCellDialog::GoToCellDialog(QWidget *parent)
:QDialog(parent),
ui(new Ui::GoToCellDialog)
{
ui->setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp, this));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
}
GoToCellDialog::~GoToCellDialog()
{
delete ui;
}
void GoToCellDialog::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
To copy to clipboard, switch view to plain text mode
The main source code:
#include "gotocelldialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
GoToCellDialog w;
w.show();
return a.exec();
}
#include "gotocelldialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GoToCellDialog w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
There's also a .ui file that contains a label, lineEdit, okButton and cancelButton. Please help me solve this error. Thanks in advance.
Bookmarks