QtCreater增加自动添加注释的快捷代码

本文介绍了如何在Qt Creator中使用预定义关键字自动生成函数注释、文件头信息,包括日期、文件名等,并展示了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在QtCreater中,可以通过添加一些关键字来自动生成一些信息,比如注释信息;

方法如下

工具–>选项:
1
添加关键字以及文本:
下面的%{CurrentDate:yyyy-MM-dd}是去时间的。
2

设置好以后点击OK,返回试一下效果:
3
然后按回车,注释信息就上去了:
4

函数注释信息
/***************************************************************
* @function name: 
* @摘要            
* @输入参数
* @输出参数          无
* @返回值            void
* @author           fensnote
* @date             %{CurrentDate:yyyy-MM-dd} 
**************************************************************/

文件头信息

如果是文件头信息的话,可以把文件名也自动提取上,如下代码:

/******************************************************************************

  Copyright (C), 2017-2027, fensnote@163.com, Ltd.

 ******************************************************************************
  File Name     : %{CurrentDocument:FileName} 
  Version       : 1.0
  Author        : fensnote
  Created       : %{CurrentDate:yyyy-MM-dd} 
  Last Modified :
  Description   :  header file
  Function List :
  History       :
  1.Date        : %{CurrentDate:yyyy-MM-dd} 
    Author      : fensnote
    Modification: Created file

******************************************************************************/

效果是这样的:

/******************************************************************************
  
  Copyright (C), 2017-2027, fensnote@163.com, Ltd.
  
 ******************************************************************************
  File Name     : main.cpp 
  Version       : 1.0
  Author        : fensnote
  Created       : 2022-04-13 
  Last Modified :
  Description   :  header file
  Function List :
  History       :
  1.Date        : 2022-04-13 
    Author      : fensnote
    Modification: Created file
    
******************************************************************************/
附内部变量
%{#:<value>
%{Config:DefaultProjectDirectory}
%{Config:LastFileDialogDirectory}
%{Cpp:LicenseTemplate}
%{Cpp:LicenseTemplatePath:FileBaseName}
%{Cpp:LicenseTemplatePath:FileName}
%{Cpp:LicenseTemplatePath:FilePath}
%{Cpp:LicenseTemplatePath:NativeFilePath}
%{Cpp:LicenseTemplatePath:NativePath}
%{Cpp:LicenseTemplatePath:Path}
%{CurrentBuild:Env:<value>}
%{CurrentBuild:Name}
%{CurrentBuild:Type}
%{CurrentDate:<value>}
%{CurrentDate:ISO}
%{CurrentDate:Locale}
%{CurrentDate:RFC}
%{CurrentDevice:HostAddress}
%{CurrentDevice:PrivateKeyFile}
%{CurrentDevice:SshPort}
%{CurrentDevice:UserName}
%{CurrentDocument:Column}
%{CurrentDocument:ColumnCount}
%{CurrentDocument:FileBaseName}
%{CurrentDocument:FileName}
%{CurrentDocument:FilePath}
%{CurrentDocument:FontSize}
%{CurrentDocument:NativeFilePath}
%{CurrentDocument:NativePath}
%{CurrentDocument:Path}
%{CurrentDocument:Row}
%{CurrentDocument:RowCount}
%{CurrentDocument:Selection}
%{CurrentDocument:XPos}
%{CurrentDocument:YPos}
%{CurrentKit:FileSystemName}
%{CurrentKit:Id}
%{CurrentKit:Name}
%{CurrentProject:BuildPath}
%{CurrentProject:FileBaseName}
%{CurrentProject:FileName}
%{CurrentProject:FilePath}
%{CurrentProject:Name}
%{CurrentProject:NativeFilePath}
%{CurrentProject:NativePath}
%{CurrentProject:Path}
%{CurrentProject:QT_HOST_BINS}
%{CurrentProject:VcsName}
%{CurrentProject:VcsTopLevelPath}
%{CurrentProject:VcsTopic}
%{CurrentRun:Executable:FileBaseName}
%{CurrentRun:Executable:FileName}
%{CurrentRun:Executable:FilePath}
%{CurrentRun:Executable:NativeFilePath}
%{CurrentRun:Executable:NativePath}
%{CurrentRun:Executable:Path}
%{CurrentRun:Name}
%{CurrentTime:<value>}
%{CurrentTime:ISO}
%{CurrentTime:Locale}
%{CurrentTime:RFC}
%{Env:<value>}
%{HostOs:ExecutableSuffix}
%{HostOs:PathListSeparator}
%{HostOs:isLinux}
%{HostOs:isOSX}
%{HostOs:isUnix}
%{HostOs:isWindows}
%{IDE:ResourcePath}
%{JS:<value>}
%{Session:FileBaseName}
%{Session:FileName}
%{Session:FilePath}
%{Session:Name}
%{Session:NativeFilePath}
%{Session:NativePath}
%{Session:Path}
%{UUID}

欢迎关注微信公众号:
1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fensnote

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值