mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-01-15 17:02:06 +08:00
Fixed new line issue
This commit is contained in:
parent
5e5d92e058
commit
ff14d2b59d
@ -2,8 +2,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor. Checks and fires up LocalServer or closes the
|
* @brief Constructor. Checks and fires up LocalServer or closes the program
|
||||||
program
|
|
||||||
* if another instance already exists
|
* if another instance already exists
|
||||||
* @param argc
|
* @param argc
|
||||||
* @param argv
|
* @param argv
|
||||||
@ -11,8 +10,7 @@ program
|
|||||||
SingleApplication::SingleApplication(int argc, char *argv[])
|
SingleApplication::SingleApplication(int argc, char *argv[])
|
||||||
: QApplication(argc, argv)
|
: QApplication(argc, argv)
|
||||||
{
|
{
|
||||||
QString serverName = QApplication::organizationName() +
|
QString serverName = QApplication::organizationName() + QApplication::applicationName();
|
||||||
QApplication::applicationName();
|
|
||||||
serverName.replace(QRegExp("[^\\w\\-. ]"), "");
|
serverName.replace(QRegExp("[^\\w\\-. ]"), "");
|
||||||
|
|
||||||
// Attempt to connect to the LocalServer
|
// Attempt to connect to the LocalServer
|
||||||
@ -20,16 +18,14 @@ QApplication::applicationName();
|
|||||||
socket->connectToServer(serverName);
|
socket->connectToServer(serverName);
|
||||||
if(socket->waitForConnected(1000)){
|
if(socket->waitForConnected(1000)){
|
||||||
socket->close();
|
socket->close();
|
||||||
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's
|
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's exit function
|
||||||
exit function
|
|
||||||
} else {
|
} else {
|
||||||
// If the connection is insuccessful, this is the main process
|
// If the connection is insuccessful, this is the main process
|
||||||
// So we create a Local Server
|
// So we create a Local Server
|
||||||
server = new QLocalServer();
|
server = new QLocalServer();
|
||||||
server->removeServer(serverName);
|
server->removeServer(serverName);
|
||||||
server->listen(serverName);
|
server->listen(serverName);
|
||||||
QObject::connect(server, SIGNAL(newConnection()), this,
|
QObject::connect(server, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished()));
|
||||||
SLOT(slotConnectionEstablished()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,4 +45,3 @@ void SingleApplication::slotConnectionEstablished()
|
|||||||
server->nextPendingConnection();
|
server->nextPendingConnection();
|
||||||
emit showUp();
|
emit showUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
#include <QLocalServer>
|
#include <QLocalServer>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The SingleApplication class handles multipe instances of the
|
* @brief The SingleApplication class handles multipe instances of the same Application
|
||||||
same Application
|
|
||||||
* @see QApplication
|
* @see QApplication
|
||||||
*/
|
*/
|
||||||
class SingleApplication : public QApplication
|
class SingleApplication : public QApplication
|
||||||
@ -30,4 +29,3 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // SINGLE_APPLICATION_H
|
#endif // SINGLE_APPLICATION_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user