Hello!
I'm trying to build the menu structure according to the directory content (with subfolders as submenus). Here is my way:
void create_menu_from_dir
(QObject *handler,
const char *method
)
{
QFileInfoList lst_fi
= d.
entryInfoList (QDir::NoDotAndDotDot |
QDir::AllEntries);
{
if (fi.isDir())
{
QMenu *mni_temp
= menu
->addMenu
(fi.
fileName());
create_menu_from_dir (handler, mni_temp,
fi.path(), method);
}
else
{
//handler->connect (act, SIGNAL(triggered()), handler, method);
menu->addAction (act);
}
}
}
void create_menu_from_dir (QObject *handler,
QMenu *menu,
const QString &dir,
const char *method
)
{
QDir d (dir);
QFileInfoList lst_fi = d.entryInfoList (QDir::NoDotAndDotDot | QDir::AllEntries);
foreach (QFileInfo fi, lst_fi)
{
if (fi.isDir())
{
QMenu *mni_temp = menu->addMenu (fi.fileName());
create_menu_from_dir (handler, mni_temp,
fi.path(), method);
}
else
{
QAction *act = new QAction (fi.fileName(), menu->parentWidget());
//handler->connect (act, SIGNAL(triggered()), handler, method);
menu->addAction (act);
}
}
}
To copy to clipboard, switch view to plain text mode
And the usage is, for example:
create_menu_from_dir (this,
tMenu,
"/home/test/tmp/2",
0
);
create_menu_from_dir (this,
tMenu,
"/home/test/tmp/2",
0
);
To copy to clipboard, switch view to plain text mode
The problem is - when I call create_menu_from_dir from the create_menu_from_dir, it goes to the endless recusion. Can someone help me?
Bookmarks