我从Maya内部启动UI.如果UI尚未关闭,再次运行UI将完全冻结Maya(错误"事件循环已在运行")
在重新运行脚本之前手动关闭UI将阻止它冻结.但我想这不太实际.
有没有办法检测我正在尝试运行的UI是否已经存在?可能的力量关闭它?
现在,我有1个应用程序,但我不想打开应用程序两次,因此我QShareMemory在打开两次时使用检测应用程序.我的问题是:当用户打开第二个应用程序时,我如何在屏幕上显示当前应用程序?
int main(int argc, char *argv[]) {
Application a(argc, argv);
/*Make sure only one instance of application can run on host system at a time*/
QSharedMemory sharedMemory;
sharedMemory.setKey ("Application");
if (!sharedMemory.create(1))
{
qDebug() << "123123Exit already a process running";
return 0;
}
/**/
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在创建一个单实例应用程序,该应用程序最小化到系统托盘,我想显示当前正在运行的实例,然后退出新实例。我怎样才能创建这个功能?
主程序
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QIcon>
#include <QQuickWidget>
#include <QSystemTrayIcon>
#include <QQmlContext>
#include <QQmlEngine>
#include <QSystemSemaphore>
#include <QSharedMemory>
// Declare a user-defined data type to work with an icon in QML
Q_DECLARE_METATYPE(QSystemTrayIcon::ActivationReason)
Q_DECL_EXPORT int main(int argc, char *argv[])
{
#if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication app(argc, argv);
QQmlApplicationEngine engine;
QSystemSemaphore semaphore("deploy", 1); // create semaphore
semaphore.acquire(); // Raise the semaphore, barring other instances to work with shared memory
#ifndef Q_OS_WIN32
// in linux / unix shared memory is not …Run Code Online (Sandbox Code Playgroud)