PDA

View Full Version : Checking if a pointer is dangling



Cruz
15th February 2009, 10:43
Hello,

does anyone know a way to detect if a pointer to a subclass of QObject or even a QWidget is dangling?



class MyWidget : public QWidget;

MyWidget w = new MyWidget(parent);

somewhere()
{
delete w;
}

somewhereelse()
{
if (w is not dangling) // <-- how to do this?
do something with w;
}


I know that you can connect the destroyed() signal, but in my case it's very tiresome. It would be much nicer (and safer) if I could somehow tell by the pointer, if it still points to a valid object or not. Is there such a path to take, oh masters of Qt?

jpn
15th February 2009, 10:52
does anyone know a way to detect if a pointer to a subclass of QObject or even a QWidget is dangling?
See QPointer.



delete w;
By the way, QObject::deleteLater() is safer to use especially when it comes to widgets.

Cruz
15th February 2009, 11:11
I just can't say it enough. Qt is the best thing since sliced bread.

talk2amulya
15th February 2009, 12:06
u r right man, QT is the best step one can take on the path to "application software humanity"..i m so glad to be a QTarian..are u? :D

jpn
15th February 2009, 12:09
QT is the best step...
You mean Qt, right? :)

talk2amulya
15th February 2009, 12:24
totally..u r not a fan of QT? cmon, u r like the GURU of this thing..u've got to be in love with it!

jpn
15th February 2009, 12:31
totally..u r not a fan of QT? cmon, u r like the GURU of this thing..u've got to be in love with it!
Yes, I'm a huge fan of Qt. But my point was that QT refers to Apple's QuickTime. You probably mean Qt, the toolkit by Qt Software/Nokia. :)

Cruz
15th February 2009, 12:58
All the way through studying computer science my fellows and I were always talking, wouldn't it be dreamy if we had a programing language, which has the nice syntax of Java but doesn't have the gay virtual machine, that slows everything down just to check the array boundaries and to clean up the garbage for you? And there you go, Qt is it! You get 99% of what Java offers AND the speed of C++. Hang on, I need to wipe a tear here.

talk2amulya
15th February 2009, 13:13
keep on passin the tissue man, cuz this community is gonna get bigger.. and u r so right about the GAY virtual machine of java..its about time that java guys need to stand up and take a bow at QT..and the whole world to recognize the power of QT..here is to QT!