关闭

qt中信号和槽的总结

372人阅读 评论(0) 收藏 举报
connect (sender,SIGNAL(signal),receiver,SLOT(slot));
1,一个信号可以被连接到多个槽。
connect(slider, SIGNAL(valueChanged(int)),
        spinBox, SLOT(setValue(int)));
connect(slider, SIGNAL(valueChanged(int)),
        this, SLOT(updateStatusBarIndicator(int)));
当这个信号被发射的时候,这些槽会一个一个的以任意的顺序被调用。 When the signal is emitted, the slots are called one after the other, in an arbitrary order.
2,多个信号可以被连接到一个槽。
connect(lcd, SIGNAL(overflow()),
        this, SLOT(handleMathError()));
connect(calculator, SIGNAL(divisionByZero()),
        this, SLOT(handleMathError()));
只要其中的一个信号被发射,这个槽就会被调用。When either signal is emitted, the slot is called.
3,一个信号可以被连接到另外一个信号。
connect(lineEdit, SIGNAL(textChanged(const QString &)),
        this, SIGNAL(updateRecord(const QString &)));
当第一个信号被发射时,第二个信号也会被发射,除此之外,信号到信号的连接和信号到槽的连接是难以区分的。When the first signal is emitted, the second signal is emitted as well. Apart from that, signal–signal connections are indistinguishable from signal–slot connections.
4,连接可以被断开。
disconnect(lcd, SIGNAL(overflow()),
           this, SLOT(handleMathError()));
This is rarely needed, because Qt automatically removes all connections involving an object when that object is deleted.
When connecting a signal to a slot (or to another signal), they must both have the same parameter types in the same order:
connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
        this, SLOT(processReply(int, const QString &)));

Exceptionally, if a signal has more parameters than the slot it is connected to, the additional parameters are simply ignored:
connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
        this, SLOT(checkErrorCode(int)));

If the parameter types are incompatible, or if the signal or the slot doesn't exist, Qt will issue a warning at run-time. Similarly, Qt will give a warning if parameter names are included in the signal or slot signatures.
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6007次
    • 积分:163
    • 等级:
    • 排名:千里之外
    • 原创:7篇
    • 转载:3篇
    • 译文:0篇
    • 评论:0条
    文章分类