Solved QLocalServer crashes when QString is used instead of "string_literal"
-
Hi everyone,
Qt application is crashing for me when I use "string_literal" instead of QString in QLocalServer::listen .
Here's my code :
SingleInstance::SingleInstance(int argc, char *argv[]) : QApplication(argc, argv), mServerName("foo") { mLocalSocket = new QLocalSocket(); mLocalSocket->connectToServer(mServerName); if (mLocalSocket->waitForConnected(mTimeToWait)) { askForMainWindow(); ::exit(0); } mLocalServer = new QLocalServer(); mLocalServer->setSocketOptions(QLocalServer::UserAccessOption); connect(mLocalServer, &QLocalServer::newConnection, this, &SingleInstance::clientConnected); mLocalServer->listen(mServerName); }
This is crashing for me. And if replace mServerName with "foo".
Does anyone know the reason for this ?
(BTW this class is inheriting QApplication and event loop hasn't been started yet.)Here 's backtrace :
(gdb) bt #0 0x00007ffff60210ca in strlen () from /usr/lib/libc.so.6 #1 0x00007ffff6e63c41 in QCoreApplication::arguments() () from /usr/lib/libQt5Core.so.5 #2 0x00007fffed464fb2 in ?? () from /usr/lib/libQt5XcbQpa.so.5 #3 0x00007fffed465bb4 in ?? () from /usr/lib/libQt5XcbQpa.so.5 #4 0x00007fffecfe9c38 in _SmcProcessMessage () from /usr/lib/libSM.so.6 #5 0x00007fffecdd946c in IceProcessMessages () from /usr/lib/libICE.so.6 #6 0x00007ffff6e8f31a in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib/libQt5Core.so.5 #7 0x00007ffff6f0f21e in QSocketNotifier::activated(int, QSocketNotifier::QPrivateSignal) () from /usr/lib/libQt5Core.so.5 #8 0x00007ffff6e9be3b in QSocketNotifier::event(QEvent*) () from /usr/lib/libQt5Core.so.5 #9 0x00007ffff78a79ac in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/libQt5Widgets.so.5 #10 0x00007ffff78ace86 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/libQt5Widgets.so.5 #11 0x00007ffff6e60bab in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/libQt5Core.so.5 #12 0x00007ffff6eb7a1d in ?? () from /usr/lib/libQt5Core.so.5 #13 0x00007ffff586cdc7 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0 #14 0x00007ffff586d020 in ?? () from /usr/lib/libglib-2.0.so.0 #15 0x00007ffff586d0cc in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0 #16 0x00007ffff6eb754f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQt5Core.so.5 #17 0x00007ffff6e5e57a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQt5Core.so.5 #18 0x00007ffff6e6653c in QCoreApplication::exec() () from /usr/lib/libQt5Core.so.5 #19 0x00000000004351c0 in main (argc=1, argv=0x7fffffffe4a8) at /home/phantom/devel/sdm/main.cpp:31
Is this a bug in Qt ?
Moreover, I'm using Qt5.5.1 and gcc version 5.3.0 (GCC)
-
Hi,
Not a direct answer but are you trying to reimplement QtSingleApplication ?
-
-
Why not use it ? IIRC It's been ported to Qt 5
-
-
It's in the QtSolution module and there's a fix for Qt 5.5 so yes, it's been ported :)
-
@SGaist said:
It's in the QtSolution module and there's a fix for Qt 5.5 so yes, it's been ported :)
Okay, Thanks a lot :)