在 Qt 中使用 C++ 运算符作为槽

问题描述 投票:0回答:1

我想知道是否可以(以及如何)使用 C++ 运算符,例如 ()、[] 作为 Qt 插槽。

编译器似乎在抱怨这个简单的代码

class MainWindowDecorator : public QObject
{  Q_OBJECT
private:
//some variables

public slots:
    int operator[](int i)
    {
    return i;
    }
}

错误如下:

Error: Not a signal or slot declaration
c++ qt signals-slots
1个回答
1
投票

您可以创建调用专用

operator
的插槽包装器。

问题在于

moc
解析器不允许该定义,可能是因为它需要标识符而不是关键字。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.