Results 1 to 3 of 3

Thread: How to explicitely delete a QDir?

  1. #1
    Join Date
    Feb 2006
    Location
    de
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to explicitely delete a QDir?

    Hi,

    using QT 3.3.4 on amd64 KUbuntu breezy,
    I'm trying to delete a QDir I created in a QObject created in a QWidget. The routine is the following:

    Qt Code:
    1. void mount::mountCheck() // check if directory is mounted (more then 2 entries)
    2. {
    3. QDir d( sMDir );
    4. if( d.count() > 2) { // more then 2 entries, dir mounted ('.', '..' + something)
    5. emit sigMOk();
    6. // ????? delete d here ?????
    7. } else {
    8. mountProc();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Running through this the 1st time works well, but coming here a second time crashes the program - system becomes unresponsive.
    I suspect the QDir d is not deleted as the QObject is not deleted either, which is OK, I need it later. Defining QDir d a 2nd time might cause the fault.

    Could somebody please give me the magic line of code how to delete the QDir d at the remark line in above code?
    The QDir Class Reference says:
    QDir::~QDir () [virtual]
    Destroys the QDir frees up its resources.
    However, I cannot transfer this in a valid line of code. Whatever I try, I always get compile errors.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to explicitely delete a QDir?

    Quote Originally Posted by alan
    Could somebody please give me the magic line of code how to delete the QDir d at the remark line in above code?
    You have created that d variable on the stack, so it will be destroyed automatically when it goes out of scope. Furthermore every time you invoke that method a new instance of QDir will be created, so it shoudn't cause any problems.

    Quote Originally Posted by alan
    Running through this the 1st time works well, but coming here a second time crashes the program - system becomes unresponsive.
    So your program crashes or hangs? What does mountProc() does? Maybe you have some infinite recursion? What did you connect to sigMOk() signal?

  3. #3
    Join Date
    Feb 2006
    Location
    de
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to explicitely delete a QDir?

    Thanks jacek!

    That was a quick answer, indeed!
    You are right:
    I just came here to update that this piece of code is OK and my program screws up later, but before the last signal could be evaluated and my output widget (feedback) would be updated, only to find you already pointed this out.
    The missing output of the widget made me think, that the error was in this function.
    I'm not a debugging guru but a few qmessageboxes at the right place...

    Thanks again for the quick answer. I'll now have to investigate the code further down the road...
    It's not in mountProc(), as this is not called in my test run, but in the code following the return of the 2nd visit of the function in question. (mountProc() will give me more headache later... :-) )

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 12:10
  2. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 16:38

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.