QAction *action = new QAction("Copy", this); QString data = "Copy data"; action->setData(data);
QMenu *menu = new QMenu("File", this); QAction *openAction = new QAction("Open", this); QString filePath = "/home/user/file.txt"; openAction->setData(filePath);In this example, we are creating a new QMenu object with the label "File" and creating an QAction object with the label "Open". We are then setting the additional data as a QString object that contains a file path. Package library: QAction class is a part of Qt Core library.