Qt Slots and C++11 lambda

后端 未结 3 698
渐次进展
渐次进展 2020-12-07 11:21

I have a QAction item that I initialize like follows:

QAction* action = foo->addAction(tr(\"Some Action\"));
connect(action, SIGNAL(triggered()), this, SL         


        
3条回答
  •  失恋的感觉
    2020-12-07 12:04

    Without "this" context, e.g. from main():

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QLabel lbl{"Hello World!"};
        QPushButton btn;
        btn.show();
        lbl.show();
    
        QObject::connect(&btn, &QPushButton::clicked, [&lbl](){lbl.setText("Button clicked");});
    
        return a.exec();
    }
    

提交回复
热议问题