21,464
社区成员
发帖
与我相关
我的任务
分享
#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;
}