From afaf2ca73c552dc57b0f5e509ba0f89ff1c33a9a Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 17 Jan 2015 13:06:22 +0100 Subject: [PATCH] tests: fix QCoreApplication parameters The argument count (first parameter) is a reference, and thus must be kept alive for the whole lifetime of the QCoreApplication instance, as also the Qt apidocs say. Also properly create a "string array" for the actual args, instead of badly casting a string to that. This fixes sporadic crashes in this test. --- src/tests/TestImport.cpp | 6 +++--- src/tests/TestImport.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tests/TestImport.cpp b/src/tests/TestImport.cpp index d4817378..2738211a 100644 --- a/src/tests/TestImport.cpp +++ b/src/tests/TestImport.cpp @@ -14,9 +14,9 @@ TestImport::TestImport() // Init basic application // The app needs to be initialized for the utf8 test // to work - int argcount = 1; - const char* appname = "sqlb-unittests"; - app = new QCoreApplication(argcount, const_cast(&appname)); + argcount = 1; + args[0] = "sqlb-unittests"; + app = new QCoreApplication(argcount, args); } TestImport::~TestImport() diff --git a/src/tests/TestImport.h b/src/tests/TestImport.h index 32b49f25..e9edb3f9 100644 --- a/src/tests/TestImport.h +++ b/src/tests/TestImport.h @@ -13,6 +13,8 @@ public: ~TestImport(); private: + int argcount; + char *args[1]; // the size must match what 'argcount' is set to QCoreApplication* app; private slots: