PDA

View Full Version : How to explicitely delete a QDir?



alan
13th February 2006, 17:34
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:


void mount::mountCheck() // check if directory is mounted (more then 2 entries)
{
QDir d( sMDir );
if( d.count() > 2) { // more then 2 entries, dir mounted ('.', '..' + something)
emit sigMOk();
// ????? delete d here ?????
} else {
mountProc();
}
}

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.

jacek
13th February 2006, 17:43
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.


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?

alan
13th February 2006, 18:48
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... :-) )