Results 1 to 3 of 3

Thread: endless recursion with QDir

  1. #1
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default endless recursion with QDir

    Hello!
    I'm trying to build the menu structure according to the directory content (with subfolders as submenus). Here is my way:
    Qt Code:
    1. void create_menu_from_dir (QObject *handler,
    2. QMenu *menu,
    3. const QString &dir,
    4. const char *method
    5. )
    6. {
    7. QDir d (dir);
    8. QFileInfoList lst_fi = d.entryInfoList (QDir::NoDotAndDotDot | QDir::AllEntries);
    9.  
    10. foreach (QFileInfo fi, lst_fi)
    11. {
    12. if (fi.isDir())
    13. {
    14. QMenu *mni_temp = menu->addMenu (fi.fileName());
    15. create_menu_from_dir (handler, mni_temp,
    16. fi.path(), method);
    17. }
    18. else
    19. {
    20. QAction *act = new QAction (fi.fileName(), menu->parentWidget());
    21. //handler->connect (act, SIGNAL(triggered()), handler, method);
    22. menu->addAction (act);
    23. }
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    And the usage is, for example:

    Qt Code:
    1. create_menu_from_dir (this,
    2. tMenu,
    3. "/home/test/tmp/2",
    4. 0
    5. );
    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: endless recursion with QDir

    Try:
    Qt Code:
    1. create_menu_from_dir (handler, mni_temp,
    2. fi.filePath(), method);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    roxton (16th January 2009)

  4. #3
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: endless recursion with QDir

    It works, thanks a lot!

Similar Threads

  1. How to explicitely delete a QDir?
    By alan in forum Newbie
    Replies: 2
    Last Post: 13th February 2006, 17:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.