查找单实例Qt应用程序的QWidget [英] Find QWidget of single instance Qt application
本文介绍了查找单实例Qt应用程序的QWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个单实例Qt应用程序,我的目标,这是工作,但现在我想要聚焦已经启动的实例,当一秒开始。
QWidget :: find(g_hWnd)应该返回小部件,但它失败,并在w-> show();崩溃崩溃
I'm trying to create a single instance Qt application and I'm at the point this works, but now I want to focus the already started instance when a second is started. QWidget::find(g_hWnd) should return the widget but it fails and crashes on w->show();
任何想法?
#pragma data_seg("Shared")
HWND g_hWnd = NULL;
#pragma data_seg()
#pragma comment(linker,"/section:Shared,rws")
int main(int argc, char *argv[])
{
if (g_hWnd)
{
QWidget* w = QWidget::find(g_hWnd);
w->show();
return 0;
}
else
{
QApplication a(argc, argv);
mainWindow w;
w.show();
g_hWnd = a.topLevelWidgets().at(0)->winId(); //or w.winId()?
return a.exec();
}
}
编辑:我现在看到Trolltech发布了 LtpL下的QtSingleApplication 类别。
edit: I now see Trolltech released the QtSingleApplication class under LGPL.
推荐答案
您应该使用 qtsingleapplication API
edit-这是一个单独的下载查看此处 LGPL和商业版本
edit- It's a separate download see here for both LGPL and Commercial editions
这篇关于查找单实例Qt应用程序的QWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文