Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5689591
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类: C/C++

2007-02-01 16:46:50

在QT中,我们一般习惯于用connect进行信号和槽的对应,但是实际上QT还提供了一种自动对应信号槽的机制。

A Dialog With Auto-Connect

Although it is easy to implement a custom slot in the dialog and connect it in the constructor, we could instead use 's auto-connection facilities to connect the OK button's clicked() signal to a slot in our subclass. uic automatically generates code in the dialog's setupUi() function to do this, so we only need to declare and implement a slot with a name that follows a standard convention:

 void on__();

Using this convention, we can define and implement a slot that responds to mouse clicks on the OK button:

 class ImageDialog : public QDialog, private Ui::ImageDialog
{
Q_OBJECT

public:
ImageDialog(QWidget *parent = 0);

private slots:
void on_okButton_clicked();
};

Automatic connection of signals and slots provides both a standard naming convention and an explicit interface for widget designers to work to. By providing source code that implements a given interface, user interface designers can check that their designs actually work without having to write code themselves.


阅读(4390) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~