16,819
社区成员




#include <QtGui/QApplication>
#include <QSharedMemory>
#include <QDebug>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
int ret = 0;
QSharedMemory sharedMemory("UniqueNameForApplication");
if (sharedMemory.create(1) && sharedMemory.error() != QSharedMemory::AlreadyExists)
{
qDebug() << "This is the only instance";
QApplication a(argc, argv);
MainWindow w;
w.show();
ret = a.exec();
}
else
{
qDebug() << "This is not the first instance";
}
return ret;
}