是否可以在没有接收器实例的情况下将信号连接到静态插槽?
像这样:connect(&object, SIGNAL(some()), STATIC_SLOT(staticFooMember()));
有一个QApplication::closeAllWindows()
Qt 文档中具有 [static slot] 属性的函数。文档中有一个使用它的示例:
exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcuts(QKeySequence::Quit);
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
是否允许执行相同的操作但不传递实例变量(例如,当类只有静态函数时)?
class Some : public QObject {
Q_OBJECT
public slots:
static void foo();
private:
Some();
};
也许 Frank Osterfeld 是对的,在这种情况下最好使用单例模式,但我仍然很惊讶为什么这个功能还没有实现。
Update:
在 Qt 5 中可以 http://woboq.com/blog/new-signals-slots-syntax-in-qt5.html.