PDA

View Full Version : QDockWidget: Debugging crash



carsten
7th January 2006, 10:41
Hi

I am porting Kalzium from Qt3 to Qt4. The last Qt3-class which needed porting is the toolbox, which is in a QDockWindow (Qt3) and now in a QDockWidget (Qt 4.1).

This is a screenshot of the Qt3.5-version. I am talking about the widget on the left.
http://edu.kde.org/kalzium/pics/screen1.png


Everything looks fine so far, but when I click on the little area on top of the window (directly over the word "Overview") it crashes. You can read the sourcecode here: http://websvn.kde.org/trunk/KDE/kdeedu/kalzium/src/kalzium.cpp?rev=494861&view=log

The QDockWidget is created here:



m_toolbox = new QToolBox( this );
m_dockWin = new QDockWidget("test");

m_dockWin->setWidget( m_toolbox );
m_dockWin->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );


this is the KMainWindow. The widgets in the QToolBox work as expected, the crash only happens if you click on the small area.

Ideas?

axeljaeger
7th January 2006, 10:52
Isn't a dockwidget without parent bad? I can imagine that the dockwidget tries to communicate with the mainWindow when you click on the header for dock/undock purposes.

Edit:

At least, you miss some addDockWidget() calls.

MarkoSan
7th January 2006, 10:53
Between line 1 ans 2 insert:


Q_CHECK_PTR(m_toolBox);
In line 3 insert:


Q_CHECK_PTR(m_dockWin);

so we can see if pointer are ok. If that is ok, than we'll move forward.

carsten
7th January 2006, 11:07
#0 0xb6a51dea in QWidget::d_func (this=0x0) at qwidget.h:115
#1 0xb6a4571d in QWidget::layout (this=0x0) at kernel/qwidget.cpp:6075
#2 0xb6c6cf1c in QDockWidgetPrivate::mousePressEvent (this=0x81377f0, event=0xbfe6c184) at widgets/qdockwidget.cpp:345
#3 0xb6c6dadf in QDockWidget::event (this=0x81361e0, event=0xbfe6c184) at widgets/qdockwidget.cpp:815
#4 0xb6a058ad in QApplicationPrivate::notify_helper (this=0x80aaa28, receiver=0x81361e0, e=0xbfe6c184) at kernel/qapplication.cpp:3116
#5 0xb6a06348 in QApplication::notify (this=0xbfe6c754, receiver=0x81361e0, e=0xbfe6c184) at kernel/qapplication.cpp:2849
#6 0xb71f7b36 in KApplication::notify (this=0xbfe6c754, receiver=0x81361e0, event=0xbfe6c184) at /home/kde4/svn/kdelibs4_snapshot/kdecore/kapplication.cpp:404
#7 0xb6a0d5e7 in QCoreApplication::sendSpontaneousEvent (receiver=0x81361e0, event=0xbfe6c184) at qcoreapplication.h:174
#8 0xb6a64d2c in QETWidget::translateMouseEvent (this=0x81361e0, event=0xbfe6c5e0) at kernel/qapplication_x11.cpp:3576
#9 0xb6a62d14 in QApplication::x11ProcessEvent (this=0xbfe6c754, event=0xbfe6c5e0) at kernel/qapplication_x11.cpp:2701
#10 0xb6a7473f in QEventDispatcherX11::processEvents (this=0x80af2c8, flags=@0xbfe6c694) at kernel/qeventdispatcher_x11.cpp:112
#11 0xb66bdf56 in QEventLoop::processEvents (this=0xbfe6c70c, flags=@0xbfe6c6cc) at kernel/qeventloop.cpp:118
#12 0xb66be1e1 in QEventLoop::exec (this=0xbfe6c70c, flags=@0xbfe6c714) at kernel/qeventloop.cpp:158
#13 0xb66c33ea in QCoreApplication::exec () at kernel/qcoreapplication.cpp:661
#14 0xb6a05045 in QApplication::exec () at kernel/qapplication.cpp:2664
#15 0x08066415 in main (argc=1, argv=0xbfe6c824) at /home/kde4/svn/kdeedu/kalzium/src/main.cpp:93

MarkoSan
7th January 2006, 11:09
Did you insert Q_CHECK_PTR as I said?

axeljaeger
7th January 2006, 11:16
I still think that the parent() of the QDockWidget is 0.

MarkoSan
7th January 2006, 11:32
So, the code:


m_dockWin = new QDockWidget("test");

should be:


m_dockWin=new QDockWidget(QString("test"), this);

axeljaeger
7th January 2006, 11:35
Either this or the dock widgets should be added later using addDockWidget. I think this sets the parent too.

carsten
7th January 2006, 11:40
This is the current code, still crashing. As soon as I make the m_dockWin a child of "this" it is *in* the mainwindow. So that cannot be right.



m_dockWin = new QDockWidget("test");
Q_CHECK_PTR( m_dockWin );

m_toolbox = new QToolBox( this );
Q_CHECK_PTR( m_toolbox );

m_dockWin->setWidget( m_toolbox );
m_dockWin->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );



I noticed this in the shell when executing Kalzium

QLayout::addChildWidget: QToolBox "" in wrong parent; moved to correct parent

class Kalzium is:



Kalzium::Kalzium()
: KMainWindow( 0, "Kalzium" )
{


I don't know the check-pointer-macro, but I don't see any information in the shell. Is this supposed to help in gdb?

MarkoSan
7th January 2006, 11:42
Like axeljaeger said, you should also use addDockWidget().

carsten
7th January 2006, 11:50
Ok, I just debugged a little more. The problem seems to be that KMainWindow does *not* inherit from QMainWindow but from Q3MainWindow. And Q3MainWindow doesn't know anything about QDockWidget but only about QDockWindow. Therefore, somewhere in the Q3Compatlib it crashes.
So somebody needs to port KMainWindow of KDE4 first.