Qt QSharedMemory(共享内存)实现单例进程

#include 
#include 
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QSharedMemory shared("A10032-GCD33259-129972"); 	//共享内存唯一标识
    if( !shared.create( 512, QSharedMemory::ReadWrite) )
    {
        QMessageBox::critical(0, "错误", "检测到未完全退出的软件,启动失败!");
        return 0;
    }
    Widget w;
    w.show();
    return a.exec();
}

你可能感兴趣的:(Qt,qt,linux,c++)