QT Creator新建工程使用自定义创建模板
模板文件夹放置位置:
Tools\QtCreator\share\qtcreator\templates\wizards
例如我这边做的模板protocol
最主要的内容就是上面箭头所指的xml文件,有的好像也有json格式的,但是内容大差不差
下面我把我里面写的xml文件的内容放在下面,大家可以参考
<?xml version="1.0" encoding="utf-8"?>
<wizard version="1" kind="project"
class="qmakeproject" firstpage="10"
id="zvit backend business plugin" category="G.Library">
<icon>logo.ico</icon>
<description>Creates a C++ plugin to load extensions dynamically into applications using the QDeclarativeEngine class. Requires Qt 4.7.0 or newer.</description>
<displayname>Zvit Backend Business Plugin</displayname>
<displaycategory>Library</displaycategory>
<files>
<file source="Interface/IApp.h" target="Interface/IApp.h"/>
<file source="Interface/extend_func_def.h" target="Interface/extend_func_def.h"/>
<file source="communication/communicationdef.h" target="communication/communicationdef.h"/>
<file source="communication/communicationglobal.h" target="communication/communicationglobal.h"/>
<file source="common/common.pri" target="common/common.pri"/>
<file source="common/DataAreaDeal.cpp" target="common/DataAreaDeal.cpp"/>
<file source="common/DataAreaDeal.h" target="common/DataAreaDeal.h"/>
<file source="common/protocol.h" target="common/protocol.h"/>
<file source="common/protocol_extend.cpp" target="common/protocol_extend.cpp"/>
<file source="common/protocol_global.h" target="common/protocol_global.h"/>
<file source="common/protocol_interface.cpp" target="common/protocol_interface.cpp"/>
<file source="common/protocol_interface.h" target="common/protocol_interface.h"/>
<file source="common/protocol_type.h" target="common/protocol_type.h"/>
<file source="common/service.cpp" target="common/service.cpp"/>
<file source="common/service.h" target="common/service.h"/>
<file source="common/service_def.h" target="common/service_def.h"/>
<file source="common/typedefheader.h" target="common/typedefheader.h"/>
<file source="common/ValueChangeDeal.cpp" target="common/ValueChangeDeal.cpp"/>
<file source="common/ValueChangeDeal.h" target="common/ValueChangeDeal.h"/>
<file source="protocol/file.h" target="%ProjectName:l%/%ProjectName:l%.%CppHeaderSuffix%"/>
<file source="protocol/file.cpp" target="%ProjectName:l%/%ProjectName:l%.%CppSourceSuffix%"/>
<file source="protocol/protocol.cpp" target="%ProjectName:l%/protocol.cpp"/>
<file source="protocol/protocol.pro" target="%ProjectName:l%/%ProjectName:l%.pro" openproject="true"/>
</files>
</wizard>
2.使用nsis制作qt creator更新包来更新上面的自定义工程模板
nsis的使用我就不多说了,网上一搜一大把
下面我把我的安装包脚本放出来供大家参考:
!define PRODUCT_NAME "Qt Creator protocol plugin project template"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_EXE_NAME "QtCreatorProtocolTemplate"
!define PRODUCT_TARGET_PATH_NAME "protocol"
!define PRODUCT_INST_PATH_KEY "Applications\QtProject.QtCreator.pro\shell\Open\Command"
!define PRODUCT_INST_PATH_ROOT_KEY "HKCR"
SetCompressor lzma
!include "MUI.nsh"
!include "StrFunc.nsh"
!include "Library.nsh"
!include "WordFunc.nsh"
!include "FileFunc.nsh"
!include "x64.nsh"
!define MUI_ABORTWARING
;!define MUI_ICON "app.ico"
!define MUI_WELCOMEPAGE_TITLE "欢迎使用“${PRODUCT_NAME}”更新向导"
!define MUI_WELCOMEPAGE_TEXT "\r\n点击[安装]开始“${PRODUCT_NAME}”的升级\r\n\r\n\r\n\r\n更新(${PRODUCT_VERSION})"
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
Name "${PRODUCT_NAME}(${PRODUCT_VERSION})(更新)"
OutFile "${PRODUCT_EXE_NAME}_upgrade(${PRODUCT_VERSION}).exe"
ShowInstDetails show
ShowUnInstDetails show
BrandingText $PRODUCT_NAME
Section -Upgrade
DetailPrint "正在Qt Creator组件..."
;SetDetailsPrint none
SetAutoClose false
SetOutPath "$INSTDIR\${PRODUCT_TARGET_PATH_NAME}\"
SetOverwrite on
File /r "${PRODUCT_TARGET_PATH_NAME}\*.*"
SectionEnd
Function .onInit
;禁止多个安装程序同时运行
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "VAUpdate") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "升级程序已经在运行。"
Abort
ClearErrors
;获取Qt Creator安装目录
ReadRegStr $R1 ${PRODUCT_INST_PATH_ROOT_KEY} ${PRODUCT_INST_PATH_KEY} ""
${WordFind} $R1 "$\"" +1 $R2
;MessageBox MB_OK $R2
${WordFind} $R2 "\bin" "+1{" $R3
;MessageBox MB_OK $R3
${WordReplace} $R3 "\\" "\" +1 $R4
;MessageBox MB_OK $R4
StrCpy $INSTDIR $R4\share\qtcreator\templates\wizards
;MessageBox MB_OK $INSTDIR
FunctionEnd