Details
-
Bug
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
No Version
-
None
-
Windows 7, Qt 5.2.1/5.4.2. MSVC2010, Latest QtService from git.
Description
If you have this test case:
#include "service.h" #include <QDebug> #include <QThread> Service::Service(int argc, char *argv[]) : QtService<QCoreApplication>(argc, argv, "test-service") { } void Service::start() { qDebug("Started"); QThread::sleep(20); //time to attach debugger qApp->arguments(); //crashes here when started from command line with -s qDebug("arguments() successfully called"); }
It will crash at qApp()->arguments() if you start it using cmd.exe:
- Start -> cmd.exe -> RMB -> "Run as Administrator"
- navigate to test-qtservice.exe (or whatever it is named)
- execute "test-qtservice.exe -s"
- Attach windbg or other debugger
- Expect crash (after QThread::sleep())
Backtrace:
0020d5b8 66899d18 00610000 bcad895e 0056de10 Qt5Core!QString::clear+0x732 0020d5f4 75663c01 756644a5 00004e20 0020d688 Qt5Core!QCoreApplication::arguments+0x178 0020d5f8 756644a5 00004e20 0020d688 669331d1 KERNELBASE!SleepEx+0x91 0020d60c 00e612ab 0020d628 00000014 0020d62c KERNELBASE!Sleep+0xf 0020d63c 708c3205 0044b700 0044b6e8 668ba1e5 test_qtservice!Service::Service+0x5b [c:\users\vincas\code\tests\test-qtservice\service.cpp @ 8] 0020d648 668ba1e5 0044b700 bcad8ace 0044b700 QtSolutions_Service_head!QtServiceBase::exec+0xb45 0020d688 66934deb ffffffff 6689934d 0044b700 Qt5Core!QObject::event+0x1c5 0020d6f4 66899565 0056e810 0044b700 bcad8b9e Qt5Core!std::_Init_locks::operator=+0x19ee8 0020d754 668d5dd0 00000000 00000000 0056e810 Qt5Core!QCoreApplicationPrivate::sendPostedEvents+0x205 0020d7c0 769b62fa 00150062 669f2330 00000000 Qt5Core!QEventDispatcherWin32::sendPostedEvents+0x10 0020d864 769b77c4 00000000 668d69d0 00150062 USER32!gapfnScSendMessage+0x332 0020d8c4 769b788a 668d69d0 00000000 0044bad0 USER32!CharPrevW+0x138 0020f6a4 668965af 00000024 bcadaa22 00446ec0 USER32!DispatchMessageW+0xf 0020f6f0 66899fb2 00000000 bcadab96 00446ec0 Qt5Core!QEventLoop::exec+0x11f 0020f734 708c54ee bcadabde 00e63430 0020f7e0 Qt5Core!QCoreApplication::exec+0x192 0020f77c 708c68b5 00000004 708c299a bcadab0e QtSolutions_Service_head!QtServiceController::start+0x75e 0020f7d0 00e61119 bcacf9e5 00000001 00e621b0 QtSolutions_Service_head!QtServiceController::start+0x1b25 0020f7d4 bcacf9e5 00000001 00e621b0 00441518 test_qtservice!main+0x9 [c:\users\vincas\code\tests\test-qtservice\main.cpp @ 6] 0020f7f4 00e6151e 00000001 00441488 00441cb8 0xbcacf9e5 0020f838 74df337a 7efde000 0020f884 76f792e2 test_qtservice!operator++0x3e [c:\qt\5.2.1\msvc2010\include\qtcore\qstring.h @ 1127] 0020f884 76f792b5 00e6163f 7efde000 00000000 kernel32!BaseThreadInitThunk+0x12 0020f89c 00000000 00e6163f 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x36
Looks like it's related with QTSOLBUG-184, which is marked as... done?
This is inconsistency, as QtService started using Windows service manager works OK, though when started using command line "-s" switch - not.
If I add OutputDebugString lines in qtservice_win.cpp:
... OutputDebugStringA(sys->serviceArgs.join(";").toLocal8Bit()); OutputDebugStringW(GetCommandLineW()); q_ptr->createApplication(argc, argv.data()); QCoreApplication *app = QCoreApplication::instance(); if (!app) ...
...I notice (using DbgView.exe) differences in command line when started from cmd.exe:
test-service;-s C:\Users\Vincas\code\tests\test-qtservice\release\test-qtservice.exe
So, sys->serviceArgs list contains two arguments: "test-service" and "-s", while GetCommandLine(), which is also used in QCoreApplication::arguments(), has only one. If service is started from services.msc, there are one argument in both cases, and there are no crash.