Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/singleapplication.cpp b/singleapplication.cpp
index 7ae333d..516e6ed 100644
--- a/singleapplication.cpp
+++ b/singleapplication.cpp
@@ -1,47 +1,47 @@
#include "singleapplication.h"
#include <cstdlib>
/**
* @brief Constructor. Checks and fires up LocalServer or closes the program
* if another instance already exists
* @param argc
* @param argv
*/
-SingleApplication::SingleApplication(int argc, char *argv[])
+SingleApplication::SingleApplication(int &argc, char *argv[])
: QApplication(argc, argv)
{
QString serverName = QApplication::organizationName() + QApplication::applicationName();
serverName.replace(QRegExp("[^\\w\\-. ]"), "");
// Attempt to connect to the LocalServer
socket = new QLocalSocket();
socket->connectToServer(serverName);
if(socket->waitForConnected(1000)){
socket->close();
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's exit function
} else {
// If the connection is insuccessful, this is the main process
// So we create a Local Server
server = new QLocalServer();
server->removeServer(serverName);
server->listen(serverName);
QObject::connect(server, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished()));
}
}
/**
* @brief Destructor
*/
SingleApplication::~SingleApplication()
{
server->close();
}
/**
* @brief Executed when the showUp command is sent to LocalServer
*/
void SingleApplication::slotConnectionEstablished()
{
server->nextPendingConnection();
emit showUp();
}
diff --git a/singleapplication.h b/singleapplication.h
index 7fab2a7..d49f8b1 100644
--- a/singleapplication.h
+++ b/singleapplication.h
@@ -1,31 +1,31 @@
#ifndef SINGLE_APPLICATION_H
#define SINGLE_APPLICATION_H
#include <QApplication>
#include <QLocalSocket>
#include <QLocalServer>
/**
* @brief The SingleApplication class handles multipe instances of the same Application
* @see QApplication
*/
class SingleApplication : public QApplication
{
Q_OBJECT
public:
- explicit SingleApplication(int, char *[]);
+ explicit SingleApplication(int&, char *[]);
~SingleApplication();
signals:
void showUp();
private slots:
void slotConnectionEstablished();
private:
QLocalSocket *socket;
QLocalServer *server;
};
#endif // SINGLE_APPLICATION_H

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 16, 1:06 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72690
Default Alt Text
(2 KB)

Event Timeline