Skip to content

Instantly share code, notes, and snippets.

@j2doll
Created September 8, 2017 12:12
Show Gist options
  • Select an option

  • Save j2doll/cea87c07ac2b4574617329a8f6c50cf1 to your computer and use it in GitHub Desktop.

Select an option

Save j2doll/cea87c07ac2b4574617329a8f6c50cf1 to your computer and use it in GitHub Desktop.
single instance process for Qt
// qt.single.instance.cpp
//
// code from http://blog.naver.com/PostView.nhn?blogId=browniz1004&logNo=220957590867&categoryNo=15&parentCategoryNo=0&viewDate=&currentPage=8&postListTopCurrentPage=&from=postList&userTopListOpen=true&userTopListCount=5&userTopListManageOpen=false&userTopListCurrentPage=8
#include "mainwindow.h"
#include <QApplication>
#include <QSharedMemory>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QSharedMemory shared("HelloWorld");
if(!shared.create(512,QSharedMemory::ReadWrite))
{
QMessageBox::information(&w,QObject::tr("HelloWorld"),QObject::tr("It's already running"),QMessageBox::Ok);
exit(0);
}
w.show();
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment