1)編寫一個bash腳本,內容如下
#! /bin/bash
cd $1
if [ -e "Makefile" ]; then
echo ">> Makefile exists. Exec make"
make
else
echo ">> Makefile do not exists. Create a new one"
qmake -project -o debug.pro
qmake debug.pro
make
if
保存到qt_compiler.sh(文件名自定,不要與系統命令和其他程序衝突即可)
將qt_compiler.sh複製到/usr/bin目錄下
2)新建一個sublime text 3 build system
打開sbulime text,在菜單欄依次點擊Tools->Build System->New Build System
會自動新建一個配置文件,將以下內容複製進去
{
"cmd": ["qt_compiler.sh", "${file_path}", ""],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"selector":"source.h, source.cpp",
"variants":
[
{
"name": "Run",
"cme": ["./debug"]
}
]
}
保存到默認位置,文件名自定(會顯示在Build System下),但後綴名一定要是sublime-build
3)Ctrl+b編譯~
Shift+Ctrl+b運行
注意,如果添加了新文件,需要修改pro文件,將新建的文件添加進編譯列表。