zoukankan      html  css  js  c++  java
  • Qt程序的单例运行

          需要使Qt程序单例运行,最典型的实现应当是使用共享内存。网上搜一下有无官方实现方法,却无意间跑到了CuteQt的一篇文章中。共享内存(QSharedMemory)实现的单程序运行,当运行环境是UNIX时,并且程序不幸崩溃,会导致共享内存无法释放,从而无法重新运行程序

    Unix: QSharedMemory "owns" the shared memory segment. When the last thread or process that has an instance of QSharedMemory attached to a particular shared memory segment detaches from the segment by destroying its instance of QSharedMemory, the Unix kernel release the shared memory segment. But if that last thread or process crashes without running the QSharedMemory destructor, the shared memory segment survives the crash.

    然后该篇文章中又提到了使用Nokia官方解决方案(QtSingleApplication),官方解决方案中为了保证良好的跨平台性和高稳定性,使用了socket来进行进程间通讯,这意味着为了获得单例运行,需要程序发布时带着QtNetWork4.dll。哎,真是跨平台和简单实现无法两全!其中使用共享内存的解决方案CSDN一篇博客中有提到。另外有Qt Centre的WIKI上提到几种SingleApplication类的实现。如何取舍,看各位看官的需要了~

  • 相关阅读:
    C#结构
    R语言快速入门
    C#_枚举类型
    C#_数组
    C#传递参数
    C#_字符串的操作
    python-函数之命名空间作用域
    python-迭代器和生成器
    python-文件操作
    python
  • 原文地址:https://www.cnblogs.com/codingmylife/p/1795608.html
Copyright © 2011-2022 走看看