qt程序只启动一个进程

#include 

int main()
{
    QString strAppName = "programName";
    QSystemSemaphore sema(strAppName,1,QSystemSemaphore::Open);
    sema.acquire();

    QSharedMemory mem("any name");
    if (!mem.create(1))
        { 
            QMessageBox message(QMessageBox::Information,"",QString("%1%2").arg(strAppName).arg(QObject::tr("is running")));
            message.setWindowFlags(Qt::Drawer);
            message.exec();
            sema.release();   
            return 0;    
        }
    sema.release();
}

你可能感兴趣的:(QT,qt,开发语言)