对
新手有用,老鸟请跳过!
最近写了一个程序,程序运行时不想让它在任务栏上
显示图标,我采用的方法是写两个窗口A,和B,A是B的parent.
程序运行的时候首先启A,从A中再调用显示B界面,A自已隐藏起来,任务栏上的图标就会隐藏,那么B就是我要用的真正的程序
界面,达到了我的目的.
但是继续往下写,会遇到一些衍生的
问题,B中有菜单,有些需要弹出一些
对话框,现在问题就来了,如果这些对话框是B的child,根本show()不出来,如果把这些对话框的parent设为NULL,当对话框关闭的时候,程序会退出.
中间想到了用各种方法,都过不了Application的quitOnLastWindowClosed 的属性的这一关,百思不得其解啊....
星期六困难扰了我一下午,今天上班继续研究,首选看了一下帮助文档
quitOnLastWindowClosed : boolThis property holds whether the application implicitly quits when the lastwindow is closed.
The default is true.
If this property is true, the applications quits when the last visibleprimary
window (i.e. window with no parent) with the
Qt::WA_QuitOnClose attribute set isclosed. By default this attribute is set for all widgets except for sub-windows.Refer to
Qt::WindowType for a detailedlist of
Qt::Window objects.
Access functions:上面的
Qt::WA_QuitOnClose引起我的注意,它原来是QWidget的一个属性,大概意思只要是最后一个带有这样属性的顶级
窗口关闭,应用程序就会退出,那么我把菜单调用的对话框设置成这个属性是不会就解决了?思路来了,马上就去验证,对话框构造函数里加上一句:
setAttribute(Qt::WA_QuitOnClose,false);
完美解决.
总结一下:
要多看帮助文档