MCPcopy Create free account
hub / github.com/MITK/MITK / handleNewAppInstance

Function handleNewAppInstance

Utilities/qtsingleapplication/qthandlenewappinstance.cpp:41–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41QString handleNewAppInstance(QtSingleApplication *singleApp, int argc, char **argv, const QString &newInstanceArg)
42{
43 if (singleApp->isRunning())
44 {
45 QStringList args;
46 bool newInstance = false;
47 for (int i = 1; i < argc; ++i)
48 {
49 args << argv[i];
50 if (args.back().endsWith(newInstanceArg))
51 {
52 newInstance = true;
53 }
54 }
55
56 if (newInstance)
57 {
58 QString path;
59 if (!createTemporaryDir(path))
60 {
61 qCritical("Could not create temporary storage path for new application instance.");
62 exit(EXIT_FAILURE);
63 }
64 qWarning("Forcing new application instance. The application data will be written to a temporary directory.");
65 return path;
66 }
67 else
68 {
69 QByteArray ba;
70 QDataStream msg(&ba, QIODevice::WriteOnly);
71 msg << QString("$cmdLineArgs"); // This message contains command line arguments
72 msg << args;
73 if (singleApp->sendMessage(ba))
74 {
75 exit(EXIT_SUCCESS);
76 }
77 else
78 {
79 qCritical("The running application seems to be frozen.");
80 exit(EXIT_FAILURE);
81 }
82 }
83 }
84 return QString();
85}

Callers 1

Calls 5

createTemporaryDirFunction · 0.85
backMethod · 0.80
QStringClass · 0.50
isRunningMethod · 0.45
sendMessageMethod · 0.45

Tested by

no test coverage detected