PDA

View Full Version : Can I define "anonnymous" slots somehow?



agnus
18th November 2009, 21:23
Hello, I have this class:


class MyWindow : public QMainWindow {
Q_OBJECT

public:
MyWindow();

signals:
void aspectRatioChange(AspectRatio aspectRatio);

private slots:
void setAspectRatio(QAction* action);

private:
struct Impl;
std::auto_ptr<Impl> imp;
};

which works alright as it is. I would like to know if I could get rid of that setAspectRatio() private slot somehow by using an "anonymous" function (callback?) in the QObject::connect() statement. My goal is to reduce as much possible the implementation details from my header files.

Thank you

squidge
18th November 2009, 22:36
I don't get it. The connect call will fail if there's no slot to call, and tell you in the output window that the slot doesn't exist.

Perhaps you would be better with a private/public class relationship. Your internal slots go into the private class, and the public ones go into the public class. You can forward declare the private class pointer, so there's no need for its header file or definition.