qsharedmemory

QSharedMemory is not getting deleted on Application crash

杀马特。学长 韩版系。学妹 提交于 2019-12-11 00:29:34
问题 I am implementing an application using Qt C++ where I have used QSharedMemory to restrict multiple instances of the application. Relevant code segment in main.cpp is as follows, QSharedMemory sharedMemory; sharedMemory.setKey(SM_INSTANCE_KEY); if (!sharedMemory.create(1)) { QMessageBox::warning(0, "Console", "An instance of this application is already running!" ); exit(0); /* Exit, already a process is running */ } On opening the Application, I can see that a shared memory has been created

Qt: Best practice for a single instance app protection

╄→尐↘猪︶ㄣ 提交于 2019-11-26 06:19:40
问题 QSingleApplication ? QMutex ? QSharedMemory ? I\'m looking for something that will work smoothly in Windows, OSX and Linux (Ubuntu). Using Qt 4.7.1 回答1: Simple solution, that does what you want. Without network dependency (as QtSingleApplication ) and without any overhead. Usage: int main() { RunGuard guard( "some_random_key" ); if ( !guard.tryToRun() ) return 0; QAppplication a(/*...*/); // ... } RunGuard.h #ifndef RUNGUARD_H #define RUNGUARD_H #include <QObject> #include <QSharedMemory>