Skip to content

Commit afaf2ca

Browse files
committed
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.
1 parent a6bd967 commit afaf2ca

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/tests/TestImport.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ TestImport::TestImport()
1414
// Init basic application
1515
// The app needs to be initialized for the utf8 test
1616
// to work
17-
int argcount = 1;
18-
const char* appname = "sqlb-unittests";
19-
app = new QCoreApplication(argcount, const_cast<char**>(&appname));
17+
argcount = 1;
18+
args[0] = "sqlb-unittests";
19+
app = new QCoreApplication(argcount, args);
2020
}
2121

2222
TestImport::~TestImport()

src/tests/TestImport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class TestImport : public QObject
1313
~TestImport();
1414

1515
private:
16+
int argcount;
17+
char *args[1]; // the size must match what 'argcount' is set to
1618
QCoreApplication* app;
1719

1820
private slots:

0 commit comments

Comments
 (0)