// Create an action that can be connected to a menu or toolbar button QAction *action = new QAction("Open File", this); // Connect the triggered() signal of the action to a slot that will handle the opening of a file connect(action, &QAction::triggered, this, &MainWindow::openFile);
// Create an action that can be connected to a menu or toolbar button QAction *action = new QAction("Save File", this); // Connect the triggered() signal of the action to a lambda function that saves the current file connect(action, &QAction::triggered, [this]() { QFile file(m_currentFile); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream out(&file); out << m_textEdit->toPlainText(); file.close(); } });In this example, a new QAction object is created with the text "Save File". The connect() function is used to connect the triggered() signal of the action to a lambda function that saves the current file. The lambda function uses a QFile object to open the file for writing, and writes the contents of a QTextEdit widget to the file. Package Library: Qt5Widgets (part of the Qt Framework)