Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault
-
I have a Gui with a bunch of LineEdits (subclass of QLineEdit).
When I click one of them to edit the text - the app dies with Segmentation Fault...I did some trial and error in order to extract the minimal code that demonstrates the problem, and found out it may have something to do with the Style - as weird as it might sounds...
So, here's the code that causes the problem:
main.cpp:
int main(int argc, char* argv[]) { try { Controller controller(argc, argv); return controller.runApplication(); } catch (std::exception& e) { qCritical() << "Unhandled exception has occurred: " << e.what(); } return 1; }
Controller.cpp:
Controller::Controller(int argc, char* argv[]) : _app(argc, argv) { QStyle *style = QStyleFactory::create("windows"); if (!style) throw std::runtime_error("Could not load style"); QApplication::setStyle(style); } void Controller::initView() { _gui = new Gui; } int Controller::runView() { _gui->show(); return _app.exec(); } int Controller::runApplication() { initView(); return runView(); } Controller::~Controller() { // todo }
The above causes Segmentation Fault when I click one of my
LineEdit
.
Here's the log from gdb:GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /project/x86_64/parser...done. (gdb) run Starting program: /project/x86_64/.parser [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib64/libthread_db.so.1". Detaching after fork from child process 5198. >>>>>>>>>>>>>>>> THIS IS WHERE I CLICK THE LINEEDIT <<<<<<<<<<<<<<<< Program received signal SIGSEGV, Segmentation fault. 0x00007ffff5d79e71 in __strlen_sse2_pminub () from /usr/lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install attica-0.4.2-1.el7.x86_64 bzip2-libs-1.0.6-13.el7.x86_64 dbus-libs-1.6.12-17.el7.x86_64 dbusmenu-qt-0.9.2-7.el7.x86_64 elfutils-libelf-0.166-2.el7.x86_64 elfutils-libs-0.166-2.el7.x86_64 expat-2.1.0-10.el7_3.x86_64 fontconfig-2.10.95-10.el7.x86_64 freetype-2.4.11-12.el7.x86_64 gamin-0.1.10-16.el7.x86_64 glib2-2.46.2-4.el7.x86_64 glibc-2.17-157.el7_3.1.x86_64 kde-style-oxygen-4.11.19-8.el7.x86_64 kdelibs-4.14.8-5.el7_2.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.14.1-27.el7_3.x86_64 libICE-1.0.9-2.el7.x86_64 libSM-1.2.2-2.el7.x86_64 libX11-1.6.3-3.el7.x86_64 libXau-1.0.8-2.1.el7.x86_64 libXcursor-1.1.14-2.1.el7.x86_64 libXdmcp-1.1.1-6.1.el7.x86_64 libXext-1.3.3-3.el7.x86_64 libXfixes-5.0.1-2.1.el7.x86_64 libXft-2.3.2-2.el7.x86_64 libXi-1.7.4-2.el7.x86_64 libXinerama-1.1.3-2.1.el7.x86_64 libXpm-3.5.11-3.el7.x86_64 libXrandr-1.4.2-2.el7.x86_64 libXrender-0.9.8-2.1.el7.x86_64 libXtst-1.2.2-2.1.el7.x86_64 libacl-2.2.51-12.el7.x86_64 libattr-2.4.46-12.el7.x86_64 libcap-2.22-8.el7.x86_64 libcom_err-1.42.9-9.el7.x86_64 libffi-3.0.13-18.el7.x86_64 libgcc-4.8.5-11.el7.x86_64 libicu-50.1.2-15.el7.x86_64 libpng-1.5.13-7.el7_2.x86_64 libselinux-2.5-6.el7.x86_64 libstdc++-4.8.5-11.el7.x86_64 libuuid-2.23.2-33.el7.x86_64 libxcb-1.11-4.el7.x86_64 libxml2-2.9.1-6.el7_2.3.x86_64 openssl-libs-1.0.1e-60.el7_3.1.x86_64 pcre-8.32-15.el7_2.1.x86_64 qca2-2.0.3-7.el7.x86_64 qt-4.8.5-13.el7.x86_64 qt-x11-4.8.5-13.el7.x86_64 soprano-2.9.2-3.el7.x86_64 strigi-libs-0.7.7-12.20120626.el7.x86_64 systemd-libs-219-30.el7_3.7.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-17.el7.x86_64 (gdb) backtrace #0 0x00007ffff5d79e71 in __strlen_sse2_pminub () at /usr/lib64/libc.so.6 #1 0x00007ffff35f9f75 in XSetCommand () at /usr/lib64/libX11.so.6 #2 0x00007ffff35fe5d1 in XSetWMProperties () at /usr/lib64/libX11.so.6 #3 0x00007ffff735dd12 in QWidgetPrivate::create_sys(unsigned long, bool, bool) () at /usr/lib64/libQtGui.so.4 #4 0x00007ffff7313d1d in QWidget::create(unsigned long, bool, bool) () at /usr/lib64/libQtGui.so.4 #5 0x00007ffff734ac22 in setupOwner() () at /usr/lib64/libQtGui.so.4 #6 0x00007ffff734b2f5 in QClipboard::setMimeData(QMimeData*, QClipboard::Mode) () at /usr/lib64/libQtGui.so.4 #7 0x00007ffff76e5497 in QLineControl::copy(QClipboard::Mode) const () at /usr/lib64/libQtGui.so.4 #8 0x00007ffff76e48e9 in QLineEdit::mouseReleaseEvent(QMouseEvent*) () at /usr/lib64/libQtGui.so.4 #9 0x00007ffff731d9a8 in QWidget::event(QEvent*) () at /usr/lib64/libQtGui.so.4 #10 0x00007ffff76e4525 in QLineEdit::event(QEvent*) () at /usr/lib64/libQtGui.so.4 #11 0x00007ffff72cab4c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib64/libQtGui.so.4 #12 0x00007ffff72d1629 in QApplication::notify(QObject*, QEvent*) () at /usr/lib64/libQtGui.so.4 #13 0x00007ffff6d9ab2d in QCoreApplication::notifyInternal(QObject*, QEvent*) () at /usr/lib64/libQtCore.so.4 #14 0x00007ffff72d0d57 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () at /usr/lib64/libQtGui.so.4 #15 0x00007ffff73463fb in QETWidget::translateMouseEvent(_XEvent const*) () at /usr/lib64/libQtGui.so.4 #16 0x00007ffff7344e6c in QApplication::x11ProcessEvent(_XEvent*) () at /usr/lib64/libQtGui.so.4 #17 0x00007ffff736c834 in x11EventSourceDispatch(_GSource*, int (*)(void*), void*) () at /usr/lib64/libQtGui.so.4 #18 0x00007ffff5726d7a in g_main_context_dispatch () at /usr/lib64/libglib-2.0.so.0 #19 0x00007ffff57270b8 in g_main_context_iterate.isra.24 () at /usr/lib64/libglib-2.0.so.0 #20 0x00007ffff572716c in g_main_context_iteration () at /usr/lib64/libglib-2.0.so.0 #21 0x00007ffff6dc95d5 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib64/libQtCore.so.4 #22 0x00007ffff736c9b6 in QGuiEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib64/libQtGui.so.4 #23 0x00007ffff6d9965f in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib64/libQtCore.so.4 #24 0x00007ffff6d999ad in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib64/libQtCore.so.4 #25 0x00007ffff6d9eeb9 in QCoreApplication::exec() () at /usr/lib64/libQtCore.so.4 #26 0x000000000040b2ef in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ../controller/main.cpp:8
But when I change the above code to this:
Controller::Controller(int argc, char* argv[]) : _app(argc, argv) { /*QStyle *style = QStyleFactory::create("windows"); if (!style) throw std::runtime_error("Could not load style");*/ QApplication::setStyle(new QWindowsStyle); }
The problem is gone! (or, hidden... which is worst)
Now, I should mention that I use Qt4 which is no longer supported, for the slim chance that this might be a lib issue.
I don't know if it's important enough, but I can also attach the (minimal) implementation of myLineEdit
.
It seems like the seg fault occur when I invokeQLineEdit::setSelection(start, 1)
, but I am not sure... <<EDIT>> yes, when I comment it out - no seg fault...Any help would be greatly appreciated.
-
@Absurd
so you are trying to run the windows style under Linux??? o.O
Also where/when is your QApplication instance created? -
Thanks for your reply.
@raven-worx said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
so you are trying to run the windows style under Linux??? o.O
Yes, the Linux Look & Feel looks horrible. Widgets looks literally deformed for some reason.
@raven-worx said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
Also where/when is your QApplication instance created?
It's a data member of
Controller
.
Controller.h:class Controller : public QObject { public: Controller(int argc, char* argv[]); ~Controller(); int runApplication(); private: QApplication _app; Gui* _gui; void initView(); int runView(); };
As you can see in the first post, it is initialized in the
Controller
's Constructor (using 'initializer list'). -
@Absurd said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
Yes, the Linux Look & Feel looks horrible. Widgets looks literally deformed for some reason.
Honestly i thought this won't even be possible. Maybe thats only the case for
WindowsVista
style?
You may also want to try the fusion style (which is platform independent:QApplication::setStyle(QStyleFactory::create("Fusion"));
@Absurd said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
As you can see in the first post, it is initialized in the Controller's Constructor (using 'initializer list').
the docs of QApplication::setStyle() mention:
Warning: To ensure that the application's style is set correctly, it is best to call this function before the QApplication constructor, if possible.
-
Thanks!
@raven-worx said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
Honestly i thought this won't even be possible. Maybe thats only the case for
WindowsVista
style?
You may also want to try the fusion style (which is platform independent:QApplication::setStyle(QStyleFactory::create("Fusion"));
QStyleFactory::create()
returns null when I use "Fusion" (or "fusion").@raven-worx said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
the docs of QApplication::setStyle() mention:
Warning: To ensure that the application's style is set correctly, it is best to call this function before the QApplication constructor, if possible.
This indeed made the Seg fault go away...
Controller::Controller(int argc, char* argv[]) { QStyle *style = QStyleFactory::create("windows"); if (!style) throw std::runtime_error("Could not load style"); QApplication::setStyle(style); _app = new QApplication(argc, argv); }
But I don't understand... what does that have to do with the seg fault? How is a Segmentation Fault at
QLineEdit::setSelection()
related to order in whichQApplication::setStyle()
andQApplication(argc, argv)
are invoked? -
@Absurd said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
QStyleFactory::create() returns null when I use "Fusion" (or "fusion").
what Qt version are you using?
@Absurd said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
But I don't understand... what does that have to do with the seg fault? How is a Segmentation Fault at QLineEdit::setSelection() related to order in which QApplication::setStyle() and QApplication(argc, argv) are invoked?
it still may be that the call stack is corrupted due to the crash
-
Thanks @raven-worx
They mention "if possible", so why is something that can potentially be as fatal as stack corruption is only mentioned as a "recommendation"?I am using Qt 4.8.5.
-
@Absurd said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
They mention "if possible", so why is something that can potentially be as fatal as stack corruption is only mentioned as a "recommendation"?
Qt docs are not perfect, but almost ;)
Also there might be a special constellation where it can lead to a crash (but not necessarily) or simply an unfixed bug, etc.@Absurd said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
I am using Qt 4.8.5
ah yes, i knew i read that but couldn't find it on a second glance.
IIRC the fusion style was introduced in Qt 5 -
@raven-worx ok, great, thanks!
@raven-worx said in Using QStyleWindows created from QStyleFactory::create kills app with Segmentation Fault:
ah yes, i knew i read that but couldn't find it on a second glance.
IIRC the fusion style was introduced in Qt 5I'll give it a try once I'll find the energy to upgrade to Qt5. :)