【Qt】学习笔记(一)

1.setupUi(this) : setupUi(this)是由.ui文件生成的类的构造函数这个函数的作用是对界面进行初始化它按照我们在Qt设计器里设计的样子把窗体画出来

setupUi(this)会自动把符合on_objectName_signalName()命名的任意槽与相应的objectName的signalName()连接在一起。即

void GoToCellDialog::on_lineEdit_textChanged()
{
      okButton->setEnabled(lineEdit->hasAcceptableInput());
}

上述代码中隐含了:

connect(lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(on_lineEdit_textChanged()));

2.

QRegExp  regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp, this));

设置检验器来限制输入范围。有三种内置检验器:QIntValidator、QDoubleValidator、QRegExpValidator.
QRegExpValidator带一个正则表达式[A-Za-z][1-9][0-9]{0,2}表示,允许一个大写或小写字母,后面跟一个1-9的数字,后再跟0、1、2个0-9的数字。

3. 类中用slots、signals时,类最开始声明 Q_OBJECT 没有分号

原文地址:https://www.cnblogs.com/dplearning/p/3808486.html