linello
linello

Reputation: 8714

Using c++ operators as slots in Qt

I'm wondering if it is possible (and how) to use c++ operators, for example (), [] as Qt slots.

It seems that the compiler is complaining about this simple code

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

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

The error is the following:

Error: Not a signal or slot declaration

Upvotes: 2

Views: 792

Answers (1)

hate-engine
hate-engine

Reputation: 2350

You can create slot wrapper that would call dedicated operator.

The problem is that moc parser disallows that definition, probably because it expects an identifier and not a keyword.

Upvotes: 1

Related Questions