当前位置:编程学习 > wap >>

谁看过C++ GUI Qt4第二版? 第二章的一个例子,,, 求解

connect(lineEdit,SIGNAL(textChanged(const QString &)),
this,SLOT(enableFindButton(const QString &)));
这里为什么用的是this 而不是findButton --------------------编程问答-------------------- this是指当前类,关键是enableFindButton的做了什么 --------------------编程问答-------------------- enableFindButton是当前类定义的一个槽函数,所以应该连接的事this --------------------编程问答-------------------- 可是这条语句是第一单元的:   QObject::connect(spinBox, SIGNAL(valueChanged(int)),
                                                slider, SLOT(setValue(int))); 这里是slider 而不是this啊 。
我是这样理解的:connect(lineEdit,SIGNAL(textChanged(const QString &)),
this,SLOT(enableFindButton(const QString &)));lineEdit改变发出textChanged信号,然后让Find按钮有效,即执行槽enableFindButton,与类无关啊 我理解的是不是不对吗? 可是第一章的例子看看用的就不是this,到底该怎么理解呢?  --------------------编程问答--------------------
引用 3 楼 wjh199133 的回复:
可是这条语句是第一单元的:   QObject::connect(spinBox, SIGNAL(valueChanged(int)),
                                                slider, SLOT(setValue(int))); 这里是slider 而不是this啊 。
我是这样理解的:connect(lineEdit,SIGNAL(textChanged(const QString &)),
this,SLOT(enableFindButton(const QString &)));lineEdit改变发出textChanged信号,然后让Find按钮有效,即执行槽enableFindButton,与类无关啊 我理解的是不是不对吗? 可是第一章的例子看看用的就不是this,到底该怎么理解呢? 

这个要看你要连接的槽函数在哪 --------------------编程问答-------------------- enableFindButton(const QString &)  这个槽函数在哪个类或对象里,接收者就写该对象或类的指针。
这里因为enableFindButton(const QString &)函数定义在当前类。所以用this,表示当前类指针。 --------------------编程问答--------------------
引用 3 楼 wjh199133 的回复:
可是这条语句是第一单元的:   QObject::connect(spinBox, SIGNAL(valueChanged(int)),
                                                slider, SLOT(setValue(int))); 这里是slider 而不是this啊 。
我是这样理解的:connect(lineEdit,SIGNAL(textChanged(const QString &)),
this,SLOT(enableFindButton(const QString &)));lineEdit改变发出textChanged信号,然后让Find按钮有效,即执行槽enableFindButton,与类无关啊 我理解的是不是不对吗? 可是第一章的例子看看用的就不是this,到底该怎么理解呢? 


从帮助文档中,你可以发现setValue(int)是QSlider这个类的函数。所以这里接收者为QSlider的对象指针slider,同理,enableFindButton(const QString &)是你自己定义类中的函数。所以这里用this --------------------编程问答-------------------- 给你个链接自己看看,http://www.189works.com/article-42143-1.html  或者直接百度C++类中的this指针,你会得到更详细的解答,也会有更清晰的理解! --------------------编程问答-------------------- lineEdit文本发生变化时要通过enableFindButton来判断是否启用findButton --------------------编程问答-------------------- enableFindButton(const QString &) 这个槽是FINDDIALOG的  this代表FINDDIALOG  enableFindButton(const QString &)操作的是FindButton  --------------------编程问答-------------------- 谢谢各位 ,谢谢 chengchaoopppo --------------------编程问答-------------------- 表示一旦信号发射就会调用当前类的enableFindButton方法
补充:移动开发 ,  Qt
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,