日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Qt::WA_QuitOnClose用法

發(fā)布時間:2023/12/15 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt::WA_QuitOnClose用法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Qt官方助手對該標(biāo)志的解釋如下:

Makes Qt quit the application when the last widget with the attribute set has accepted closeEvent(). This behavior can be modified with the QApplication::quitOnLastWindowClosed property. By default this attribute is set for all widgets of type Qt::Window.

大意是:

? 當(dāng)最后一個設(shè)置了本屬性的窗體部件關(guān)閉時(即接受了closeEvent()事件)退出應(yīng)用程序。這個屬性可以被QApplication::quitOnLastWindowClosed函數(shù)修改。對所有類型為Qt::Window.的窗體,這個屬性默認(rèn)被設(shè)置為true。

如下:

#include "QtWidgetsApplication1.h" #include "QtTestWidget.h" QtWidgetsApplication1::QtWidgetsApplication1(QWidget* parent): QWidget(parent) {ui.setupUi(this);setWindowTitle("WidgetsApplication1");// setAttribute(Qt::WA_QuitOnClose, false);m_pTestWidget = new QtTestWidget();m_pTestWidget->show(); }QtWidgetsApplication1::~QtWidgetsApplication1() {}

其中?m_pTestWidget是QtWidgetsApplication1的成員變量,類型為:QtTestWidget。QtTestWidget.cpp如下:

#include "QtTestWidget.h"QtTestWidget::QtTestWidget(QWidget *parent): QWidget(parent) {ui.setupUi(this);setWindowTitle("TestWidget"); // setAttribute(Qt::WA_QuitOnClose, false); }QtTestWidget::~QtTestWidget() { }

彈出標(biāo)題為:WidgetsApplication1、TestWidget兩個窗體。按Qt助手的解釋:這兩個窗體的Qt::WA_QuitOnClose默認(rèn)都為true,所以先關(guān)閉其中任何一個窗體,程序不會退出,只有當(dāng)最后一個窗體關(guān)閉時,應(yīng)用程序才退出。

? 當(dāng)將QtWidgetsApplication1.cpp構(gòu)造函數(shù)中的setAttribute(Qt::WA_QuitOnClose, false);注釋去掉,則:

a):關(guān)閉WidgetsApplication1窗體,程序不退出關(guān)閉TestWidget窗體,程序才退出。因?yàn)榇藭rWidgetsApplication1窗體的Qt::WA_QuitOnClose為false,即剔除了該屬性;TestWidget窗體的Qt::WA_QuitOnClose依然為true,即TestWidget窗體是包含Qt::WA_QuitOnClose屬性的最后一個窗體,當(dāng)最后一個包含Qt::WA_QuitOnClose屬性的窗體退出時,程序退出。

b):先關(guān)閉TestWidget窗體,程序退出。道理同a)條目所述。

? 當(dāng)將QtWidgetsApplication1.cpp、QtTestWidget.cpp構(gòu)造函數(shù)中的setAttribute(Qt::WA_QuitOnClose, false);注釋都去掉,無論先關(guān)閉哪個窗體或兩個窗體都關(guān)閉,應(yīng)用程序都不會退出

總結(jié)

以上是生活随笔為你收集整理的Qt::WA_QuitOnClose用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。