My problem is to make a menu to load files. Here's my code:
QStringList fileNameList;
fileNameList << "file1" << "file2" << "file3";
QMenuBar *menubar = new QMenuBar();
QMenu *menu = menubar->addMenu("File");
QMenu *load = menu->addMenu("Load");
foreach (QString fileName, fileNameList) {
QAction *loadFile = new QAction(fileName, this);
load->addAction(loadFile);
connect(load,SIGNAL(triggered(QAction*)),this, SLOT(load(QAction*)));
}
And a slot:
void MainWindow::load(QAction* action) {
qDebug() << action->text();
}
After I click any action button, qDebug shows:
"file1"
"file1"
"file1"
But I need to run that action only once! QAction does not have a signal from which I can get its name. How to solve this? Thank you!