MCPcopy Create free account
hub / github.com/IJHack/QtPass / sendMessage

Method sendMessage

src/singleapplication.cpp:74–99  ·  view source on GitHub ↗

* @brief SingleApplication::sendMessage send a message (from commandline) to an * already running QtPass instance. * @param message * @return */

Source from the content-addressed store, hash-verified

72 * @return
73 */
74auto SingleApplication::sendMessage(const QString &message) -> bool {
75 if (!_isRunning) {
76 return false;
77 }
78 QLocalSocket localSocket(this);
79 localSocket.connectToServer(_uniqueKey, QIODevice::WriteOnly);
80 if (!localSocket.waitForConnected(timeout)) {
81#ifdef QT_DEBUG
82 dbg() << localSocket.errorString().toLatin1();
83#endif
84 return false;
85 }
86 QByteArray payload = message.toUtf8();
87 if (payload.isEmpty()) {
88 payload = QByteArray(1, '\0');
89 }
90 localSocket.write(payload);
91 if (!localSocket.waitForBytesWritten(timeout)) {
92#ifdef QT_DEBUG
93 dbg() << localSocket.errorString().toLatin1();
94#endif
95 return false;
96 }
97 localSocket.disconnectFromServer();
98 return true;
99}

Callers 1

mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected