Qt编程用自己格式写的槽一般要做槽链接,而通过ui界面转到槽则不需要。查看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 QMetaObject'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 OKbutton: 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. 就是说如果槽的命名是这样的话:void on__(); 就会自动将widget name中的信号signal name和这个槽void on__()链接起来。 这是QT不需要connect语句就可以自动链接信号和槽的机制!
|