PDA

View Full Version : endless recursion with QDir



roxton
16th January 2009, 20:35
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,
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);
}
}
}


And the usage is, for example:



create_menu_from_dir (this,
tMenu,
"/home/test/tmp/2",
0
);


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? :)

jpn
16th January 2009, 20:57
Try:


create_menu_from_dir (handler, mni_temp,
fi.filePath(), method);

roxton
16th January 2009, 23:04
It works, thanks a lot!