PDA

View Full Version : Qt Plugin causing segmentation faults



MSUdom5
11th June 2013, 21:41
I've run into an interesting situation that causes unpredictable segfaults when my application exits. I tried to isolate an example in a small project, but was unable to reproduce it. I think I know the cause, but would like an expert's opinion.

I have a static libary, FooLib, which contains several classes (including an abstract base class, FooInterface). Some classes have static member data. I also have a Qt Plugin, FooPlugin, which depends on FooLib and implements FooInterface. My main application also depends on FooLib.

I'm able to load the plugin and use it without any issues. However, when the application exits, I get a segfault. (If I run it through a debugger, there is not segfault, so I can't get a stack trace). If I remove all static member data from the classes in FooLib, the segfault goes away.

My guess is that the static member data is being deleted twice, once when FooPlugin is unloaded, and again when FooLib classes (instatiated in my main application) are destructed.

Any thoughts from experts?

Thanks ,

karankumar1609
12th June 2013, 06:14
I have got the same problem in my APP.
Then i debug it and found that, I have created a static pointer in a class and and the pointer gets deleted whenever the object of that class is deleted.

The cause happen when i use the same static variable class in my parent as well as child class.

One more mistake i have made is that i have created an object of static variable class in main.cpp and also created object in mainwindow.cpp....
:P
If you accessing the deleted object then obviously it cause ERROR...