- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 QApplication
,其中有一个自定义的 QDialog
。该对话框为用户提供一组选项,然后通过 QProcess
启动一个进程。虽然启动的进程仍在运行,但应用程序如果已关闭则仍必须运行。为此,我重新实现了 QWidget
的 closeEvent
和 accept()
ed 或 ignore()
ed基于进程是否启动的事件。
在 closeEvent()
函数中,我隐藏了我的 QDialog
。这样,对于用户来说,应用程序就关闭了(但是它将在任务管理器中运行)。我希望用户通过再次运行程序来重新启动应用程序。此时我需要弄清楚另一个实例已经在运行并且该实例应该出现在前台。
谁能帮我实现这个目标?
最佳答案
命名互斥量可以用来解决。
这article很有帮助。
WINAPI WinMain(
HINSTANCE, HINSTANCE, LPSTR, int)
{
try {
// Try to open the mutex.
HANDLE hMutex = OpenMutex(
MUTEX_ALL_ACCESS, 0, "MyApp1.0");
if (!hMutex)
// Mutex doesn’t exist. This is
// the first instance so create
// the mutex.
hMutex =
CreateMutex(0, 0, "MyApp1.0");
else
// The mutex exists so this is the
// the second instance so return.
return 0;
Application->Initialize();
Application->CreateForm(
__classid(TForm1), &Form1);
Application->Run();
// The app is closing so release
// the mutex.
ReleaseMutex(hMutex);
}
catch (Exception &exception) {
Application->
ShowException(&exception);
}
return 0;
}
关于c++ - 在 Qt 中隐藏和重新启动同一个 QApplication 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22378529/
我想念任何Qt如果我替换 QApplication::exec() 的功能使用标准的 Windows 消息循环实现?这应该澄清我的意思: 运行事件处理的常用“Qt”方式: int main(int a
何时在 Windows 上调用虚函数 QApplication::saveState 和 QApplication::commitData?它们是否被调用,或者 session 管理只是 UNIX 的
有两个qApplications A & B,它们可以在各自的主窗口中分别执行。 我想实现以下目标: 1) //Open Application B. //Inside App B's code
我正在尝试运行一个简单的 hello world 示例,并且已经需要一些时间来弄清楚要使用的内容现在我验证了包含路径,QApplication 实际上应该在那里,但它抛出了上述错误。为了清楚起见,我的
当我首先运行 python-pyside2 项目服务器时,它运行良好。 而且该站点也运行良好,但是如果我按 F5 btn 在浏览器中刷新。 站点显示错误页面 Runtime at/ import sy
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我正在将 Qt 桌面应用程序移植到 Linux(Ubuntu 19.10、64 位桌面、Qt 5.12.5、gcc 版本 9.2.1),并且在 QApplication 完成后发现一些意外的线程仍然处
这里引用 Qt 文档: For any GUI application using Qt, there is precisely one QApplication object 很明显。但我不知道为什
这里引用 Qt 文档: For any GUI application using Qt, there is precisely one QApplication object 很明显。但我不知道为什
我正在尝试将修改后的 qt 程序作为库运行。我需要它而不是阻止主执行。 所以我想做的是运行 QApplication 并开始执行主应用程序。我该如何实现? 我的第一个想法是在一个单独的线程中运行它。
我需要在单击按钮时重新启动我的应用程序,但我遇到了一些问题。我尝试了两种方法: 已尝试 this suggestion它确实重新启动了应用程序,但是我得到了每个小部件的 Gtk_IS_INVISIBL
我试图在不同的线程中创建 QApplication,但发现了 2 个主要问题: 1- 我无法与 GUI 交互 2- 一些警告: 警告:QApplication 不是在 main() 线程中创建的。 Q
是否可以在退出前一个实例后创建和使用新的 QApplication 实例? 最佳答案 是的,您可以在销毁前一个实例后创建一个新的 QApplication。我在 Windows 中使用 PyQt4 验
我是 PyQt4(和 QT)的新手,我遇到了一个问题, 我已经对 QApplication 进行了子类化(以具有对应用程序真正全局的全局数据和函数): class App(QApplication):
我正在 3Dsmax 2015 上做一些简单的 PySide。 这是我的错误: python.ExecuteFile "C:\Program Files\Autodesk\3ds Max 2015\s
我有一个带有单个对话框窗口的 Qt 应用程序。主要看起来像这样: QApplication a(argc, argv); MyObject * myMobject = new QObject(&a);
我有一个带有通知区域图标的应用程序,因此主窗口可能会忽略关闭事件。我正在尝试在应用程序退出时保存首选项和历史记录。我还想在应用程序运行时处理注销。虽然该应用程序是跨平台的,但它在 GNU/Linux
QApplication::QApplication ( int & argc, char ** argv ) Initializes the window system and constructs
我应该在哪里使用 except 块来记录 QApplication 的异常? 这似乎不起作用: app = QtGui.QApplication(sys.argv) MainWindow = Main
在基本的 C++ Qt Widgets 应用程序中,在堆栈上创建一个 QApplication 或直接在 main 函数中对其进行堆分配是可行的,但是在堆上调用一个函数-分配一个 QApplicati
我是一名优秀的程序员,十分优秀!