#include <QtGui>
#include <QDebug>
{
Q_OBJECT
public:
line1->setValidator(v);
spin->setDecimals(1);
spin->setMinimum(18.0);
spin->setMaximum(39.0);
layout->addWidget(line1);
layout->addWidget(spin);
setLayout(layout);
connect(line1,
SIGNAL(textChanged
(QString)),
SLOT(slotTextChanged
(QString)));
connect(line1, SIGNAL(returnPressed()), SLOT(checkIsValid()));
connect(line1, SIGNAL(editingFinished()), SLOT(checkIsValid()));
}
public slots:
void slotTextChanged
(const QString &text
) { qDebug() << "Text changed to" << text << "and value is valid ==" << line1->hasAcceptableInput();
}
void checkIsValid() {
qDebug() << "Edit finished and value is valid ==" << line1->hasAcceptableInput();
}
};
int main(int argc, char **argv)
{
Widget w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class Widget: public QWidget
{
Q_OBJECT
QLineEdit *line1;
public:
Widget(): QWidget() {
line1 = new QLineEdit(this);
QDoubleValidator *v = new QDoubleValidator(18.5, 39.0, 1, line1);
v->setNotation(QDoubleValidator::StandardNotation);
line1->setValidator(v);
QDoubleSpinBox *spin = new QDoubleSpinBox(this);
spin->setDecimals(1);
spin->setMinimum(18.0);
spin->setMaximum(39.0);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(line1);
layout->addWidget(spin);
setLayout(layout);
connect(line1, SIGNAL(textChanged(QString)), SLOT(slotTextChanged(QString)));
connect(line1, SIGNAL(returnPressed()), SLOT(checkIsValid()));
connect(line1, SIGNAL(editingFinished()), SLOT(checkIsValid()));
}
public slots:
void slotTextChanged(const QString &text) {
qDebug() << "Text changed to" << text << "and value is valid ==" << line1->hasAcceptableInput();
}
void checkIsValid() {
qDebug() << "Edit finished and value is valid ==" << line1->hasAcceptableInput();
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks