# Qt开发_C_CPP自动代码规范格式软件 **Repository Path**: Mike_Zhou_Admin/C_Style ## Basic Information - **Project Name**: Qt开发_C_CPP自动代码规范格式软件 - **Description**: 博客和视频: https://blog.csdn.net/weixin_53403301/article/details/145940905 更新以gitee为准 - **Primary Language**: C++ - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2025-03-01 - **Last Updated**: 2025-12-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Qt开发_C_CPP自动代码规范格式软件 #### 介绍 博客和视频: https://blog.csdn.net/weixin_53403301/article/details/145940905 更新以gitee为准 #### 软件架构 # AStyle AStyle是个跨平台开源工具,Windows、Linux、macOS都能用。 下载地址:`https://sourceforge.net/projects/astyle/` AStyle的命令参数: 比如我的命令是:`-n !E --style=allman -p -s4 -S -f -xW -w -xw` `-n`不生成备份文件,原文件直接覆盖,没后悔药。 `!E`文件路径 如果在keil里面做脚本配置 这里就是替换为当前文件地址 `--style=allman`用Allman风格,大括号独占一行,代码看着清楚。 `-p`指针和运算符两边加空格,比如x=y变x = y。 `-s4`缩进用4个空格,比默认2空格更明显。 `-S`switch里的case缩进一层,结构更分明。 `-f`空的{}强制换行,格式统一。 `-xW`C++类修饰符(public/private)缩进对齐,C代码用不上。 `-w`多行条件语句加括号,比如if (a && b)变块状。 `-xw`while/do-while循环体再缩进一层,突出循环。 使用起来很简单 譬如: ```shell D:\astyle-3.6.7-x64\astyle.exe -n .\RTE\Device\STM32L496RGTx\STCubeGenerated\Src\main.c --style=allman -p -s2 -S -f -xW -w -xw ``` # Qt 在Qt中 使用`QProcess`即可实现shell命令 推荐使用函数: ```c shell.execute(cmd,arg); ``` 其中 arg是`QStringList` 譬如: ```c void MainWindow::on_pushButton_4_clicked() { uint32_t len = File_List.size(); uint32_t i =0; QString path; QString cmd; QStringList arg; arg.clear(); arg.append(""); if(this->ui->c1->checkState()) { arg.append("--style=allman"); } if(this->ui->c2->checkState()) { arg.append("-p"); } if(this->ui->c3->checkState()) { arg.append("-S"); } if(this->ui->c4->checkState()) { arg.append("-f"); } if(this->ui->c5->checkState()) { arg.append("-xW"); } if(this->ui->c6->checkState()) { arg.append("-w"); } if(this->ui->c7->checkState()) { arg.append("-xw"); } if(this->ui->comboBox->currentIndex()) { arg.append("-s4"); } else { arg.append("-s2"); } if(this->ui->c0->checkState()) { arg.append("-n"); } if(len == 0) { qDebug()<<"No File\n"; } else { for(i=0;iui->textEdit_2->setText(content); file.close();//关闭文件 } else { qDebug() << "Failed to open file\n";//showMessage("文件打开失败") } } } } ``` # 效果 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/e74e7a77effb4af686062845d8b11159.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/07ff6ca19463456d8cad4e88a28c8aa9.png)