是否可以在没有接收器实例的情况下将信号连接到静态槽?
像这样:connect(&object, SIGNAL(some()), STATIC_SLOT(staticFooMember()));
在Qt文档中有一个带有[静态槽]属性的QApplication::closeAllWindows()
函数,还有一个来自文档的使用示例:
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是正确的,使用单例模式在这种情况下更好,但我仍然惊讶为什么这个功能还没有被实现。
更新: