在Qt中,QShortcut有这样的构造函数
QShortcut(const QKeySequence& key, QWidget *parent,
const char *member = 0, const char *ambiguousMember = 0,
Qt::ShortcutContext context = Qt::WindowShortcut);据我所知,从文档中可以将一个方法传递给第三个参数,而不是使用。但是我怎样才能通过方法呢?使用
QShortcut* sh = new QShortcut(QKeySequence(Qt::Key_Alt, Qt::Key_1), this, &OnShortcut);或
QShortcut* sh = new QShortcut(QKeySequence(Qt::Key_Alt, Qt::Key_1), this, &MyClass::OnShortcut);给出错误
错误:没有调用‘Q快捷方式::q快捷键(QKeySequence,KeyPressProcessing* const,void (*)())’的匹配函数。
发布于 2015-02-20 11:53:44
您必须使用SLOT(OnShortcut())而不是&OnShortcut,因为QShortcut类构造函数需要const char *作为第二个和第三个参数,而不是指向函数的指针。因此,Qt有专门的转换宏SLOT,它接受函数签名作为参数,并以适合建立连接的形式对其进行转换。
https://stackoverflow.com/questions/28626862
复制相似问题