开发者

Crash on internal QMutex::lock when deleting QFrame subclass in dropEvent

I'm coding in C++ with OpenSUSE Linux and using Qt Creator as my IDE.

I have a QFrame subclass called Interactive that is parented to another QFrame subclass called Window. In Window::dropEvent, I want to delete event->source, which is an Interactive object. So I have a setup like this:

void Window::dropEvent(QDropEvent *event) {

  //after identifying MIME type as an Interactive object:

  Interactive *temp = (qobject_cast<Interactive*>(event->source()));
  temp->deleteLater();

}

Then it's usually fine until I try to do anything else in my program, and then I get this:

(gdb) bt
0  0xf5df218f in QMutex::lock() () from /space/cp/x86/qt/lib/libQtCore.so.4
1  0xf5f05b27 in QCoreApplication::postEvent(QObject*, QEvent*, int) () from /space/cp/x86/qt/lib/libQtCore.so.4
2  0xf5f05e5c in QCoreApplication::po开发者_StackOverflowstEvent(QObject*, QEvent*) () from /space/cp/x86/qt/lib/libQtCore.so.4
3  0xf5f15ce7 in QObject::deleteLater() () from /space/cp/x86/qt/lib/libQtCore.so.4
4  0xf62ccb00 in ?? () from /space/cp/x86/qt/lib/libQtGui.so.4
5  0xf62b31d2 in QApplication::x11ClientMessage(QWidget*, _XEvent*, bool) () from /space/cp/x86/qt/lib/libQtGui.so.4
6  0xf62bfd04 in QApplication::x11ProcessEvent(_XEvent*) () from /space/cp/x86/qt/lib/libQtGui.so.4
7  0xf62e834f in ?? () from /space/cp/x86/qt/lib/libQtGui.so.4
8  0xf5f0480a in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /space/cp/x86/qt/lib/libQtCore.so.4
9  0xf5f04c52 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /space/cp/x86/qt/lib/libQtCore.so.4
10 0xf5f06f69 in QCoreApplication::exec() () from /space/cp/x86/qt/lib/libQtCore.so.4
11 0xf6238887 in QApplication::exec() () from /space/cp/x86/qt/lib/libQtGui.so.4
12 0x0805d028 in main (argc=138177832, argv=0x83cf3b0) at /home/bbayes/DspGUI/main.cpp:10

The Interactive being deleted isn't referenced again by any of my code. This error looks completely internal to Qt. I looked around online but couldn't find a similar example or solution. Does anyone have any idea how to solve this problem?


Qt Doc says that qobject_cast:

Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns 0.

Check if your cast works or not before attempting to delete the object as below :

Interactive *temp = (qobject_cast<Interactive*>(event->source()));
if (temp != NULL)
{
   temp->deleteLater();
}


You can't delete the event->source of an event. I worked around it by appending event->source to a list to be deleted later, once this event was finished.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜