Passing an argument to a slot

后端 未结 5 2668
灰色年华
灰色年华 2020-11-22 16:15

I want to override mouseReleaseEvent with a bunch of QActions and QMenus...

connect(action1, SIGNAL(triggered()), this, SLOT(onStepIncreased()));

connect(ac         


        
5条回答
  •  时光说笑
    2020-11-22 17:00

    Maybe you can subclass QAction with an m_increase member variable.
    Connect the triggered() signal to a slot on your new QAction subclass and emit a new signal (e.g. triggered(int number)) with the correct parameter.
    e.g.

    class MyAction:public QAction  
    {  
    public:  
        MyAction(int increase, ...)  
            :QAction(...), m_increase(increase)
        {  
            connect(this, SIGNAL(triggered()), this, SLOT(onTriggered()));  
        }  
    protected Q_SLOTS:  
        void onTriggered()  
        {  
            emit triggered(m_increase);  
        }  
    
    Q_SIGNALS:
        void triggered(int increase);   
    
    private:  
        int m_increase;  
    };
    

提交回复
热议问题