#include <qapplication.h>
#include <qwidget.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qvalidator.h>
{
Q_OBJECT
public:
mojClass();
private:
private slots:
void customSlot
(const QString &input
);
};
void mojClass
::customSlot(const QString &input
) {
int num = 4 * input.toInt();
label3->setNum(num);
}
mojClass::mojClass()
{
setGeometry(100,100,300,200);
lineedit1->setGeometry(110,10,50,20);
lineedit1->setMaxLength(6);
lineedit1->setValidator(validator);
label1->setGeometry(10,10,100,20);
label1->setText("Enter something: ");
label2->setGeometry(10,40,100,20);
label2->setText("You've entered: ");
label3->setGeometry(120,40,100,20);
connect(lineedit1,
SIGNAL(textChanged
(const QString &)),
this,
SLOT(customSlot
(const QString &)));
}
int main(int argc, char **argv)
{
mojClass objekt;
a.setMainWidget(&objekt);
objekt.show();
a.exec();
}
#include <qapplication.h>
#include <qwidget.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qvalidator.h>
class mojClass : public QWidget
{
Q_OBJECT
public:
mojClass();
private:
QLineEdit *lineedit1;
QLabel *label1;
QLabel *label2;
QLabel *label3;
QValidator *validator;
private slots:
void customSlot(const QString &input);
};
void mojClass::customSlot(const QString &input)
{
int num = 4 * input.toInt();
label3->setNum(num);
}
mojClass::mojClass()
{
setGeometry(100,100,300,200);
validator = new QIntValidator(100,99999,this);
lineedit1 = new QLineEdit(this);
lineedit1->setGeometry(110,10,50,20);
lineedit1->setEchoMode(QLineEdit::Normal);
lineedit1->setMaxLength(6);
lineedit1->setValidator(validator);
label1 = new QLabel(this);
label1->setGeometry(10,10,100,20);
label1->setText("Enter something: ");
label2 = new QLabel(this);
label2->setGeometry(10,40,100,20);
label2->setText("You've entered: ");
label3 = new QLabel(this);
label3->setGeometry(120,40,100,20);
connect(lineedit1,SIGNAL(textChanged(const QString &)),this,SLOT(customSlot(const QString &)));
}
int main(int argc, char **argv)
{
QApplication a(argc,argv);
mojClass objekt;
a.setMainWidget(&objekt);
objekt.show();
a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks