Qt工作笔记-SIGNAL之textChanged
生活随笔
收集整理的这篇文章主要介绍了
Qt工作笔记-SIGNAL之textChanged
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
今天学习到的东西真的很多。在查阅以前的源码里面发现了textChanged这个信号。
不仅仅如此。关键是这让我进一步学会了如何看文档;
功能动态如下:
功能就如文档中说的那样This signal is emitted whenever the text changes. The text argument is the new text.
代码如下
widget.h
#ifndef WIDGET_H #define WIDGET_H#include <QWidget>namespace Ui { class Widget; }class Widget : public QWidget {Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();public slots:void BtnIsEnable();private:Ui::Widget *ui; };#endif // WIDGET_Hwidget.cpp
#include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui->setupUi(this);ui->pushButton->setEnabled(false);connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(BtnIsEnable())); }void Widget::BtnIsEnable(){if(ui->lineEdit->text().isEmpty()){ui->pushButton->setEnabled(false);}else{ui->pushButton->setEnabled(true);} }Widget::~Widget() {delete ui; }main.cpp
#include "widget.h" #include <QApplication>int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); }总结
以上是生活随笔为你收集整理的Qt工作笔记-SIGNAL之textChanged的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: QML与C++混合编程详解
- 下一篇: Qt工作笔记-对信号与槽的进一步理解(信