课程代码仓库初始化:Part1 (144) + Part3 (29) 全量生成与验证
把川大 wiki「02.Qt方向」课程代码整理为 CMake 管理的可编译运行项目。
Part1 C/C++ 强化 (p01/, 144 目标, host gcc/g++ 构建, 全绿):
- 修复全部编译失败:补 <cstring>/<fstream>/<iomanip>/<vector> 等缺失头
(common_fix + infer_stl_includes 自动检测注入)、修正 pause() 壳注入
(改检测已转换后的 pause 调用)、namespace 提升出函数体、const 成员函数
正确性、dedupe 不再破坏函数重载集、K&R 隐式 int / 动态异常规范等
C++17 移除特性的可编译等价改写。
- 目录采用深缩写 p01/ch04/s03/ (原 part1_cpp/ch04_class_object/03_ctor_dtor)。
Part3 Qt 桌面 (p03/, 29 目标, 隔离 Qt 5.14.2 构建, 全绿):
- gen_part3.py: Qt 外壳模板 (main+QApplication+show, QTimer 自动退出便于
offscreen 验证)、AUTOMOC + .moc include、rewrite_* 处理散文混入/重载/
资源依赖、生成占位 png/gif + .qrc + rundata 样例数据。
- 修正 QLable 笔误、全角分号、.→->、Windows 路径、QApplication 阻塞事件
循环改为 QCoreApplication 等。
任务1 概念/版本验证:
- tools/std_probe.py: 跨 -std= 编译探针 (--pedantic-errors 让已废除特性硬失败)。
- tools/demo_versions/: K&R 隐式 int、三目左值、void* 转换、enum 赋整、
const 经指针、动态异常规范 共 6 个跨版本演示。
- docs/VERSION_NOTES.md: 每条「原文说法→C17/C++17 是否成立→何版本成立→已验证」。
文档: 顶层 README、docs/SOURCE_PAGES.md (页面→目录映射)、
docs/ERRATA.md (Part1 修正)、docs/ERRATA_part3.md (Part3 修正)。
另修复 tools/run.sh / run_qt.sh 的 ${1:?...} 引号语法 bug。
隔离 Qt 验证: ldd 0 系统 Qt 引用; 173/173 目标全绿; p03 offscreen 运行通过。
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# Auto-generated by tools/gen_part3.py — do not edit by hand.
|
||||
# 章节:p03/ch06
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
add_executable(modal_dialog modal_dialog.cpp)
|
||||
set_target_properties(modal_dialog PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF AUTOMOC ON)
|
||||
target_link_libraries(modal_dialog PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
target_compile_options(modal_dialog PRIVATE -Wall -Wextra)
|
||||
add_executable(modeless_dialog_stack modeless_dialog_stack.cpp)
|
||||
set_target_properties(modeless_dialog_stack PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF AUTOMOC ON)
|
||||
target_link_libraries(modeless_dialog_stack PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
target_compile_options(modeless_dialog_stack PRIVATE -Wall -Wextra)
|
||||
add_executable(modeless_dialog_heap modeless_dialog_heap.cpp)
|
||||
set_target_properties(modeless_dialog_heap PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF AUTOMOC ON)
|
||||
target_link_libraries(modeless_dialog_heap PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
target_compile_options(modeless_dialog_heap PRIVATE -Wall -Wextra)
|
||||
add_executable(modeless_dialog_deleteonclose modeless_dialog_deleteonclose.cpp)
|
||||
set_target_properties(modeless_dialog_deleteonclose PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF AUTOMOC ON)
|
||||
target_link_libraries(modeless_dialog_deleteonclose PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
target_compile_options(modeless_dialog_deleteonclose PRIVATE -Wall -Wextra)
|
||||
add_executable(message_box_question message_box_question.cpp)
|
||||
set_target_properties(message_box_question PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF AUTOMOC ON)
|
||||
target_link_libraries(message_box_question PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
target_compile_options(message_box_question PRIVATE -Wall -Wextra)
|
||||
add_executable(message_box_custom message_box_custom.cpp)
|
||||
set_target_properties(message_box_custom PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF AUTOMOC ON)
|
||||
target_link_libraries(message_box_custom PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
target_compile_options(message_box_custom PRIVATE -Wall -Wextra)
|
||||
add_executable(file_dialog file_dialog.cpp)
|
||||
set_target_properties(file_dialog PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF AUTOMOC ON)
|
||||
target_link_libraries(file_dialog PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
target_compile_options(file_dialog PRIVATE -Wall -Wextra)
|
||||
add_custom_target(all_p03_ch06 DEPENDS modal_dialog modeless_dialog_stack modeless_dialog_heap modeless_dialog_deleteonclose message_box_question message_box_custom file_dialog)
|
||||
@@ -0,0 +1,142 @@
|
||||
# p03/ch06 — Qt 示例
|
||||
|
||||
## 可运行示例
|
||||
|
||||
| 目标 | 源文件 | 说明 |
|
||||
|---|---|---|
|
||||
| `modal_dialog` | `modal_dialog.cpp` | 构建运行见顶层 README;离屏验证 `QT_QPA_PLATFORM=offscreen tools/run_qt.sh modal_dialog` |
|
||||
| `modeless_dialog_stack` | `modeless_dialog_stack.cpp` | 构建运行见顶层 README;离屏验证 `QT_QPA_PLATFORM=offscreen tools/run_qt.sh modeless_dialog_stack` |
|
||||
| `modeless_dialog_heap` | `modeless_dialog_heap.cpp` | 构建运行见顶层 README;离屏验证 `QT_QPA_PLATFORM=offscreen tools/run_qt.sh modeless_dialog_heap` |
|
||||
| `modeless_dialog_deleteonclose` | `modeless_dialog_deleteonclose.cpp` | 构建运行见顶层 README;离屏验证 `QT_QPA_PLATFORM=offscreen tools/run_qt.sh modeless_dialog_deleteonclose` |
|
||||
| `message_box_question` | `message_box_question.cpp` | 构建运行见顶层 README;离屏验证 `QT_QPA_PLATFORM=offscreen tools/run_qt.sh message_box_question` |
|
||||
| `message_box_custom` | `message_box_custom.cpp` | 构建运行见顶层 README;离屏验证 `QT_QPA_PLATFORM=offscreen tools/run_qt.sh message_box_custom` |
|
||||
| `file_dialog` | `file_dialog.cpp` | 构建运行见顶层 README;离屏验证 `QT_QPA_PLATFORM=offscreen tools/run_qt.sh file_dialog` |
|
||||
|
||||
## 参考片段(签名/伪代码,未单独建目标)
|
||||
|
||||
### [block 4] .4 消息对话框
|
||||
|
||||
```cpp
|
||||
void about(QWidget * parent, const QString & title, const QString & text)
|
||||
```
|
||||
|
||||
### [block 5] .4 消息对话框
|
||||
|
||||
```cpp
|
||||
void aboutQt(QWidget * parent, const QString & title = QString()):
|
||||
```
|
||||
|
||||
### [block 6] .4 消息对话框
|
||||
|
||||
```cpp
|
||||
StandardButton critical(QWidget * parent,
|
||||
const QString & title,
|
||||
const QString & text,
|
||||
StandardButtons buttons = Ok,
|
||||
StandardButton defaultButton = NoButton):
|
||||
```
|
||||
|
||||
### [block 7] .4 消息对话框
|
||||
|
||||
```cpp
|
||||
StandardButton information(QWidget * parent,
|
||||
const QString & title,
|
||||
const QString & text,
|
||||
StandardButtons buttons = Ok,
|
||||
StandardButton defaultButton = NoButton)
|
||||
```
|
||||
|
||||
### [block 8] .4 消息对话框
|
||||
|
||||
```cpp
|
||||
StandardButton question(QWidget * parent,
|
||||
const QString & title,
|
||||
const QString & text,
|
||||
StandardButtons buttons = StandardButtons( Yes | No ),
|
||||
StandardButton defaultButton = NoButton)
|
||||
```
|
||||
|
||||
### [block 9] .4 消息对话框
|
||||
|
||||
```cpp
|
||||
StandardButton warning(QWidget * parent,
|
||||
const QString & title,
|
||||
const QString & text,
|
||||
StandardButtons buttons = Ok,
|
||||
StandardButton defaultButton = NoButton)
|
||||
```
|
||||
|
||||
### [block 13] 6.5 标准文件对话框
|
||||
|
||||
```cpp
|
||||
connect(openAction, &QAction::triggered,
|
||||
this, &MainWindow::openFile);
|
||||
connect(saveAction, &QAction::triggered,
|
||||
this, &MainWindow::saveFile);
|
||||
```
|
||||
|
||||
### [block 14] 6.5 标准文件对话框
|
||||
|
||||
```cpp
|
||||
//打开文件
|
||||
void MainWindow::openFile()
|
||||
{
|
||||
QString path = QFileDialog::getOpenFileName(this,
|
||||
tr("Open File"), ".", tr("Text Files(*.txt)"));
|
||||
if(!path.isEmpty())
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Read File"),
|
||||
tr("Cannot open file:\n%1").arg(path));
|
||||
return;
|
||||
}
|
||||
QTextStream in(&file);
|
||||
textEdit->setText(in.readAll());
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Path"),
|
||||
tr("You did not select any file."));
|
||||
}
|
||||
}
|
||||
|
||||
//保存文件
|
||||
void MainWindow::saveFile()
|
||||
{
|
||||
QString path = QFileDialog::getSaveFileName(this,
|
||||
tr("Open File"), ".", tr("Text Files(*.txt)"));
|
||||
if(!path.isEmpty())
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Write File"),
|
||||
tr("Cannot open file:\n%1").arg(path));
|
||||
return;
|
||||
}
|
||||
QTextStream out(&file);
|
||||
out << textEdit->toPlainText();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Path"),
|
||||
tr("You did not select any file."));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### [block 15] 6.5 标准文件对话框
|
||||
|
||||
```cpp
|
||||
QString getOpenFileName(QWidget * parent = 0,
|
||||
const QString & caption = QString(),
|
||||
const QString & dir = QString(),
|
||||
const QString & filter = QString(),
|
||||
QString * selectedFilter = 0,
|
||||
Options options = 0)
|
||||
```
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// ============================================================================
|
||||
// file_dialog — Qt 桌面示例
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 原文片段:[58954535:12]
|
||||
// 说明:本文件由 gen_part3.py 从 wiki 片段生成(必要时补 main/QApplication
|
||||
// 外壳、include、修正笔误)。详见 docs/ERRATA.md。
|
||||
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh <target>
|
||||
// ============================================================================
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QAction>
|
||||
#include <QMenuBar>
|
||||
#include <QToolBar>
|
||||
#include <QFileDialog>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWindow() {
|
||||
QAction* openAction = new QAction(QStringLiteral("打开..."), this);
|
||||
QAction* saveAction = new QAction(QStringLiteral("保存..."), this);
|
||||
menuBar()->addMenu(QStringLiteral("文件"))->addAction(openAction);
|
||||
menuBar()->addMenu(QStringLiteral("文件"))->addAction(saveAction);
|
||||
connect(openAction, &QAction::triggered, this, &MainWindow::openFile);
|
||||
connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile);
|
||||
}
|
||||
private slots:
|
||||
void openFile() {
|
||||
QString path = QFileDialog::getOpenFileName(this, QStringLiteral("打开文件"));
|
||||
if (path.isEmpty()) return;
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QMessageBox::warning(this, QStringLiteral("错误"), QStringLiteral("打开失败"));
|
||||
return;
|
||||
}
|
||||
QTextStream in(&file);
|
||||
QString text = in.readAll();
|
||||
file.close();
|
||||
QMessageBox::information(this, QStringLiteral("内容"), text);
|
||||
}
|
||||
void saveFile() {
|
||||
QString path = QFileDialog::getSaveFileName(this, QStringLiteral("保存文件"));
|
||||
if (path.isEmpty()) return;
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QMessageBox::warning(this, QStringLiteral("错误"), QStringLiteral("保存失败"));
|
||||
return;
|
||||
}
|
||||
QTextStream out(&file);
|
||||
out << QStringLiteral("示例保存内容");
|
||||
file.close();
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
MainWindow w; w.show();
|
||||
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
||||
QTimer::singleShot(200, &app, &QApplication::quit);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "file_dialog.moc"
|
||||
@@ -0,0 +1,55 @@
|
||||
// ============================================================================
|
||||
// message_box_custom — Qt 桌面示例
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 原文片段:[58954535:11]
|
||||
// 说明:本文件由 gen_part3.py 从 wiki 片段生成(必要时补 main/QApplication
|
||||
// 外壳、include、修正笔误)。详见 docs/ERRATA.md。
|
||||
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh <target>
|
||||
// ============================================================================
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
class DemoWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DemoWidget(){ doDemo(); }
|
||||
private slots:
|
||||
void doDemo(){
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("The document has been modified."));
|
||||
msgBox.setInformativeText(tr("Do you want to save your changes?"));
|
||||
msgBox.setDetailedText(tr("Differences here..."));
|
||||
msgBox.setStandardButtons(QMessageBox::Save
|
||||
| QMessageBox::Discard
|
||||
| QMessageBox::Cancel);
|
||||
msgBox.setDefaultButton(QMessageBox::Save);
|
||||
int ret = msgBox.exec();
|
||||
switch (ret)
|
||||
{
|
||||
case QMessageBox::Save:
|
||||
qDebug() << "Save document!";
|
||||
break;
|
||||
case QMessageBox::Discard:
|
||||
qDebug() << "Discard changes!";
|
||||
break;
|
||||
case QMessageBox::Cancel:
|
||||
qDebug() << "Close document!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
DemoWidget w;
|
||||
w.show();
|
||||
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
||||
QTimer::singleShot(200, &app, &QApplication::quit);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "message_box_custom.moc"
|
||||
@@ -0,0 +1,47 @@
|
||||
// ============================================================================
|
||||
// message_box_question — Qt 桌面示例
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 原文片段:[58954535:10]
|
||||
// 说明:本文件由 gen_part3.py 从 wiki 片段生成(必要时补 main/QApplication
|
||||
// 外壳、include、修正笔误)。详见 docs/ERRATA.md。
|
||||
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh <target>
|
||||
// ============================================================================
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
class DemoWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DemoWidget(){ doDemo(); }
|
||||
private slots:
|
||||
void doDemo(){
|
||||
if (QMessageBox::Yes == QMessageBox::question(this,
|
||||
tr("Question"), tr("Are you OK?"),
|
||||
QMessageBox::Yes | QMessageBox::No,
|
||||
QMessageBox::Yes))
|
||||
{
|
||||
QMessageBox::information(this, tr("Hmmm..."),
|
||||
tr("I'm glad to hear that!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::information(this, tr("Hmmm..."),
|
||||
tr("I'm sorry!"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
DemoWidget w;
|
||||
w.show();
|
||||
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
||||
QTimer::singleShot(200, &app, &QApplication::quit);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "message_box_question.moc"
|
||||
@@ -0,0 +1,36 @@
|
||||
// ============================================================================
|
||||
// modal_dialog — Qt 桌面示例
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 原文片段:[58954535:0]
|
||||
// 说明:本文件由 gen_part3.py 从 wiki 片段生成(必要时补 main/QApplication
|
||||
// 外壳、include、修正笔误)。详见 docs/ERRATA.md。
|
||||
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh <target>
|
||||
// ============================================================================
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
|
||||
class DemoWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DemoWidget(){ doDemo(); }
|
||||
private slots:
|
||||
void doDemo(){
|
||||
QDialog dialog;
|
||||
dialog.setWindowTitle(tr("Hello, dialog!"));
|
||||
dialog.exec();
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
DemoWidget w;
|
||||
w.show();
|
||||
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
||||
QTimer::singleShot(200, &app, &QApplication::quit);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "modal_dialog.moc"
|
||||
@@ -0,0 +1,37 @@
|
||||
// ============================================================================
|
||||
// modeless_dialog_deleteonclose — Qt 桌面示例
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 原文片段:[58954535:3]
|
||||
// 说明:本文件由 gen_part3.py 从 wiki 片段生成(必要时补 main/QApplication
|
||||
// 外壳、include、修正笔误)。详见 docs/ERRATA.md。
|
||||
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh <target>
|
||||
// ============================================================================
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
|
||||
class DemoWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DemoWidget(){ doDemo(); }
|
||||
private slots:
|
||||
void doDemo(){
|
||||
QDialog *dialog = new QDialog;
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->setWindowTitle(tr("Hello, dialog!"));
|
||||
dialog->show();
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
DemoWidget w;
|
||||
w.show();
|
||||
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
||||
QTimer::singleShot(200, &app, &QApplication::quit);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "modeless_dialog_deleteonclose.moc"
|
||||
@@ -0,0 +1,36 @@
|
||||
// ============================================================================
|
||||
// modeless_dialog_heap — Qt 桌面示例
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 原文片段:[58954535:2]
|
||||
// 说明:本文件由 gen_part3.py 从 wiki 片段生成(必要时补 main/QApplication
|
||||
// 外壳、include、修正笔误)。详见 docs/ERRATA.md。
|
||||
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh <target>
|
||||
// ============================================================================
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
|
||||
class DemoWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DemoWidget(){ doDemo(); }
|
||||
private slots:
|
||||
void doDemo(){
|
||||
QDialog *dialog = new QDialog;
|
||||
dialog->setWindowTitle(tr("Hello, dialog!"));
|
||||
dialog->show();
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
DemoWidget w;
|
||||
w.show();
|
||||
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
||||
QTimer::singleShot(200, &app, &QApplication::quit);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "modeless_dialog_heap.moc"
|
||||
@@ -0,0 +1,36 @@
|
||||
// ============================================================================
|
||||
// modeless_dialog_stack — Qt 桌面示例
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 原文片段:[58954535:1]
|
||||
// 说明:本文件由 gen_part3.py 从 wiki 片段生成(必要时补 main/QApplication
|
||||
// 外壳、include、修正笔误)。详见 docs/ERRATA.md。
|
||||
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh <target>
|
||||
// ============================================================================
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
|
||||
class DemoWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DemoWidget(){ doDemo(); }
|
||||
private slots:
|
||||
void doDemo(){
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle(tr("Hello, dialog!"));
|
||||
dialog.show();
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
DemoWidget w;
|
||||
w.show();
|
||||
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
||||
QTimer::singleShot(200, &app, &QApplication::quit);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "modeless_dialog_stack.moc"
|
||||
Reference in New Issue
Block a user