C++ (Qt)#ifndef MYLINE_H#define MYLINE_H #include <QLineEdit> class MyLine : public QLineEdit { Q_OBJECTpublic:explicit MyLine(QWidget *parent = 0); signals: public slots:void MySlot(const QString &strToDouble); }; #endif // MYLINE_H
C++ (Qt)#include <QDebug>#include <QRegularExpression>#include "myline.h" MyLine::MyLine(QWidget *parent) : QLineEdit(parent) { connect(this, SIGNAL(textChanged(const QString &)), SLOT(MySlot(const QString &))); } void MyLine::MySlot(const QString &strToDouble) {QRegularExpression rxpComplex("^\\d+(\\.\\d+)?$"); QString str = strToDouble;if(!str.contains(rxpComplex)) qDebug() << sender()->objectName() + " - value " + str + " is not double!"; }
C++ (Qt)#ifndef MYWIDGET_H#define MYWIDGET_H #include <QWidget> class MyWidget : public QWidget {Q_OBJECT public:MyWidget(QWidget *parent = 0); virtual ~MyWidget();}; #endif // MYWIDGET_H
C++ (Qt)#include <QtWidgets>#include "mywidget.h"#include "myline.h" MyWidget::MyWidget(QWidget *parent) : QWidget(parent) {MyLine *line1 = new MyLine;line1->setObjectName("line1");MyLine *line2 = new MyLine;line2->setObjectName("line2");MyLine *line3 = new MyLine;line3->setObjectName("line3"); QVBoxLayout *vbox = new QVBoxLayout;vbox->addWidget(line1);vbox->addWidget(line2);vbox->addWidget(line3);setLayout(vbox);}
C++ (Qt)#include <QApplication>#include "mywidget.h" int main(int argc, char *argv[]){QApplication a(argc, argv);MyWidget w;w.show(); return a.exec();}
C++ (Qt)connect (edit, &QLineEdit::textChanged, this, &MainWindow::block_symbols_in_polya)