Unsolved QLineEdit + QUndoCommand::mergeWidth crashes App
-
I am creating an application that uses the undo framework. I also use a model-view architecture for my data structure and the pimpl pattern to have a clear api to my model classes. I run however into a problem with combining QLineEdit as widget to induce changes to my model via QUndoCommands. A simplified application that has the considered problem can be downloaded here.
You can recreate the problem by entering numbers into one of the two QLineEdit boxes and do so until the notation changes to scientific syntax. Subsequently hit the undo button on the left to induce the crash. When removing the overridden QUndoCommand::mergeWith methods for my commands, the crash is gone but the behavior for the above scenario is weird. Does anybody have an idea on how to fix this?
-
Hi,
You should add:
- Which version of Qt you are using
- Which version you are running on
- A stack trace of the crash you get
-
Good question! The crash appeared on Qt5.7.1 in Ubuntu 16.04. So, I upgraded to Qt5.12.0.
What is rather annoying is that it is not completely clear under which circumstances the crash occurs. After trying several times, I got it to occur as follows: add numbers to the QLineEdit below 'Time' until the value automatically changes to scientific notation. Subsequently, undo and then perform a redo. But it seems better to play with it and perhaps restart the app so now and then to get to a crash. I am not sure how to save a stack trace, but below is something that I could copy from the debugger. In some cases, I got the following messages as application output:
07:31:04: Debugging starts OpenType support missing for "Ubuntu", script 11 OpenType support missing for "Ubuntu", script 9 OpenType support missing for "Ubuntu", script 13 OpenType support missing for "Ubuntu", script 17 07:37:26: Debugging has finished
07:37:30: Starting undo_issue/build/debug/undo_issue... 07:37:37: The program has unexpectedly finished. 07:37:37: The process was ended forcefully. 07:37:37: build/debug/undo_issue crashed.
1 QUndoCommand::actionText() const 0x7ffff7a34d20 2 QUndoStack::undoText() const 0x7ffff7a35241 3 QUndoStackPrivate::setIndex(int, bool) 0x7ffff7a3530d 4 QUndoStack::redo() 0x7ffff7a366fb 5 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff6873629 6 QAction::triggered(bool) 0x7ffff76e5882 7 QAction::activate(QAction::ActionEvent) 0x7ffff76e7ca0 8 QAbstractButtonPrivate::click() 0x7ffff77d3450 9 QAbstractButton::mouseReleaseEvent(QMouseEvent *) 0x7ffff77d3565 10 QToolButton::mouseReleaseEvent(QMouseEvent *) 0x7ffff78b192a 11 QWidget::event(QEvent *) 0x7ffff7729348 12 QToolButton::event(QEvent *) 0x7ffff78b19f9 13 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7ffff76eb85c 14 QApplication::notify(QObject *, QEvent *) 0x7ffff76f2fcf 15 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7ffff6847c18 16 QApplicationPrivate::sendMouseEvent(QWidget *, QMouseEvent *, QWidget *, QWidget *, QWidget * *, QPointer<QWidget>&, bool, bool) 0x7ffff76f1f0a 17 QWidgetWindow::handleMouseEvent(QMouseEvent *) 0x7ffff7742d4b 18 QWidgetWindow::event(QEvent *) 0x7ffff774586b 19 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7ffff76eb85c 20 QApplication::notify(QObject *, QEvent *) 0x7ffff76f29f0 21 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7ffff6847c18 22 QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *) 0x7ffff6eb01e7 23 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *) 0x7ffff6eb1795 24 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff6e8d44b 25 xcbSourceDispatch(_GSource *, int ( *)(void *), void *) 0x7fffef89c67a 26 g_main_context_dispatch 0x7ffff29c3197 27 ?? 0x7ffff29c33f0 28 g_main_context_iteration 0x7ffff29c349c 29 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff689edcf 30 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff684657a 31 QCoreApplication::exec() 0x7ffff684ef80 32 main main.cpp 10 0x4046c2
-
Well, was able to get a glimpse of some strange behavior and after hitting 'Undo' a crash. The screenshot before hitting 'Undo' and the applocation output (this was unfortunately not done in the debugger). I am slowly starting to think that the call to QObject::tr in my QUndoCommand constructors are causing the problem...
The example app can be downloaded from https://modeltech.org/temp/undo_issue.zip
Application Output:
09:30:52: Starting undo_issue/build/debug/undo_issue... OpenType support missing for "Ubuntu", script 18 OpenType support missing for "Ubuntu", script 10 OpenType support missing for "Ubuntu", script 17 OpenType support missing for "Ubuntu", script 15 09:32:31: The program has unexpectedly finished. 09:32:31: The process was ended forcefully. 09:32:31: undo_issue/build/debug/undo_issue crashed.
-
After removing the QObject::tr calls, it still crashes, but now the stack trace looks a bit different. I am not aware of a method isObsolete for QUndoCommand but it seems that there is a problem with that :?
1 QUndoCommand::isObsolete() const 0x7ffff7a34ce4 2 QUndoStack::undo() 0x7ffff7a361db 3 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff6873629 4 QAction::triggered(bool) 0x7ffff76e5882 5 QAction::activate(QAction::ActionEvent) 0x7ffff76e7ca0 6 QAbstractButtonPrivate::click() 0x7ffff77d3450 7 QAbstractButton::mouseReleaseEvent(QMouseEvent *) 0x7ffff77d3565 8 QToolButton::mouseReleaseEvent(QMouseEvent *) 0x7ffff78b192a 9 QWidget::event(QEvent *) 0x7ffff7729348 10 QToolButton::event(QEvent *) 0x7ffff78b19f9 11 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7ffff76eb85c 12 QApplication::notify(QObject *, QEvent *) 0x7ffff76f2fcf 13 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7ffff6847c18 14 QApplicationPrivate::sendMouseEvent(QWidget *, QMouseEvent *, QWidget *, QWidget *, QWidget * *, QPointer<QWidget>&, bool, bool) 0x7ffff76f1f0a 15 QWidgetWindow::handleMouseEvent(QMouseEvent *) 0x7ffff7742d4b 16 QWidgetWindow::event(QEvent *) 0x7ffff774586b 17 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7ffff76eb85c 18 QApplication::notify(QObject *, QEvent *) 0x7ffff76f29f0 19 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7ffff6847c18 20 QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *) 0x7ffff6eb01e7 21 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *) 0x7ffff6eb1795 22 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff6e8d44b 23 xcbSourceDispatch(_GSource *, int ( *)(void *), void *) 0x7fffef89c67a 24 g_main_context_dispatch 0x7ffff29c3197 25 ?? 0x7ffff29c33f0 26 g_main_context_iteration 0x7ffff29c349c 27 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff689edeb 28 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff684657a 29 QCoreApplication::exec() 0x7ffff684ef80 30 main main.cpp 10 0x4046b2
-
After completely removing the setText calls in the QUndoCommand, I still have a crash, now with yet another stack trace
1 __memmove_ssse3_back memcpy-ssse3-back.S 1544 0x7ffff5dd7e2f 2 QListData::remove(int) 0x7ffff66dbcc4 3 QUndoStack::undo() 0x7ffff7a36244 4 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff6873629 5 QAction::triggered(bool) 0x7ffff76e5882 6 QAction::activate(QAction::ActionEvent) 0x7ffff76e7ca0 7 QAbstractButtonPrivate::click() 0x7ffff77d3450 8 QAbstractButton::mouseReleaseEvent(QMouseEvent *) 0x7ffff77d3565 9 QToolButton::mouseReleaseEvent(QMouseEvent *) 0x7ffff78b192a 10 QWidget::event(QEvent *) 0x7ffff7729348 11 QToolButton::event(QEvent *) 0x7ffff78b19f9 12 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7ffff76eb85c 13 QApplication::notify(QObject *, QEvent *) 0x7ffff76f2fcf 14 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7ffff6847c18 15 QApplicationPrivate::sendMouseEvent(QWidget *, QMouseEvent *, QWidget *, QWidget *, QWidget * *, QPointer<QWidget>&, bool, bool) 0x7ffff76f1f0a 16 QWidgetWindow::handleMouseEvent(QMouseEvent *) 0x7ffff7742d4b 17 QWidgetWindow::event(QEvent *) 0x7ffff774586b 18 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7ffff76eb85c 19 QApplication::notify(QObject *, QEvent *) 0x7ffff76f29f0 20 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7ffff6847c18 21 QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *) 0x7ffff6eb01e7 22 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *) 0x7ffff6eb1795 23 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff6e8d44b 24 xcbSourceDispatch(_GSource *, int ( *)(void *), void *) 0x7fffef89c67a 25 g_main_context_dispatch 0x7ffff29c3197 26 ?? 0x7ffff29c33f0 27 g_main_context_iteration 0x7ffff29c349c 28 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff689edcf 29 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) 0x7ffff684657a 30 QCoreApplication::exec() 0x7ffff684ef80 31 main main.cpp 10 0x404642
-
Still looking for ideas / suggestions ...
-
You should try to create a minimal, compilable example so we can try to reproduce it. Or even better you'll find your problem while trying to create the example.
-
@Christian-Ehrlicher I actually did create one, but apparently I forgot to post the link... So, here it is https://modeltech.org/temp/undo_issue.zip
-
Your testapp works fine here with Qt5.11.2 on Linux. Is there something special I've to do?
-
Hmm, that is interesting. What Linux are you using? Perhaps I should downgrade back to Qt5.11.2 to see whether that would solve the issue...
-
It's also working with 5.12 / 64 bit.