首页 > 代码库 > 【Qt】学习笔记(一)
【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 没有分号
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。