2013年8月9日 星期五

[Development] qmake


  • 簡介:
    • qmake為 qt提供的 make tool, 可產生不同平台所需的 Makefile
    • .pro 為其特殊的專案檔格式
    • 重要: Qt 專案 build的過程
  • 常用變數:
    • TEMPLATE
      • 可等於 app、lib、subdirs, e.g. TEMPLATE=app, 可用來產生不同的專案類型, 產生的是應用程式、函式庫或子目錄(遞迴式搜尋子資料夾), 預設值為 app
    • HEADERS
      • 設定相關 header files
    • SOURCES
      • 指定所要 build的 c++檔
    • FORMS
      • 指定 Qt Designer產生的 .ui檔, 會呼叫 Qt的工具程式 uic來處理
    • RESOURCES
      • 由程式 rcc來處理 .qrc檔
    • DEFINES
      • 可定義預處理器符號
    • INCLUDEPATH
      • 可指定 C++搜尋目錄, 以設定全域的標頭檔案
    • LIBS
      • 指定連結至專案的函式庫, 可使用絕對路徑或 Unix的 -L, -l flags
    • CONFIG
      • 可設定多種專案與編譯器組態
        • debug
        • release
        • warn_off: default是開啓
        • qt: 預設開啓
        • dll
        • staticlib
        • plugins: 相當於 dll
        • console: 這比較重要, 表示 output需要被寫到 console window, e.g. 使用 cout、cerr等, 對於拿來寫 console application來說, 需設定此項
        • app_bundle、lib_bundle: Mac OS X專用
    • QT
      • 設定所使用的 QT modules, 預設為 core gui (QtCore與 QtGui)
    • VERSION
    • TARGET
      • app 或 lib的名稱, 不包含 prefix, version等
    • DESTDIR
      • build後的目錄
    • DLLdESTDIR
  • 產生特定平台專案檔(假設 Qt專案檔為 hello.pro)
    • General
      • qmke hello.pro, 接著可以用 make or nmake去 build
    • MicroSoft Visual Studio專案檔
      • qmake -tp vc hello.pro
    • Mac OS X 
      • Xcode project
        • qmake -spec macx-xcode hello.pro
      • makefile
        • qmake -spec macx-g++ hello.pro
      • spec選項可以指定"平台-編譯器"的組合, 如上述 macx(平台)-xcode(編譯器)
  • 自動產生 .pro檔
    • qmake -project
      • 會搜尋當前目錄中的 .cpp, .h, .ui檔以產生 .pro
  • 註解: #
  • 相關運算子
    • +=, -=
      • CONFIG = qt
      • CONFIG += release
      • CONFIG -= warn_off
    • *=
      • 當該變數為空, 則 assign, 否則不做任何動作
      • SOURCES *= main.cpp
      • 上式等同於, 若 SOURCES沒指定任何檔案, 則指定為 main.cpp
    • ~=
      • 可替換任何值, 支援 sed語法
      • SOURCES ~= s/\.cpp\b/.cxx/
      • 上式代表將所有 .cpp的附檔名改為 .cxx
  • 存取變數
    • $$variable or $${variable}  -- 在 .pro檔中的值
    • $$(variable) -- 在 qmake執行環境中的環境變數值
    • $(variable) -- makefile 執行環境中的環境變數值
    • $$[variable] -- Qt組態選項值
  • 判斷式
    • 語法
      • condition{
        • then-case
      • }else{
        • else-case
      • }
    • 其中的 condiction可為平台名稱, e.g. win32, unix, or macx, 例如:
      • win32{
        • SOURCES += serial_win.cpp
      • }else{
        • SOURCES += serial_unix.cpp
      • }
    • 單行式
      • macx: SOURCES += serial_mac.cpp
  • project include
    • include(../common.pri)
  • 利用 CMake 產生 Qt應用程式

2013年8月3日 星期六

[C++] 慣用簡潔的 pointer算式

int *p, *q分別指向 source array與 destination array, 若要 copy, 可用 *q++=*p++;

如此直接完成了三個動作:
*q=*p;
q++;
p++;

2013年7月31日 星期三

[Latex] embed fonts into PDF file


  • 若欲在 texmaker中產生內嵌字型的 pdf檔
    • 在快速編譯中, 選擇 latex+dvips+ps2pdf+瀏覽PDF
    • 在 ps2pdf中, 加入如下所示的 options
      • "/usr/local/bin/ps2pdf" -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 %.ps

2013年7月4日 星期四

[Programming] 保持乾淨的標頭檔


  • 不該無謂的 include 一堆東西, 容易造成名稱衝突
  • 不要在 header file中使用 using namespace

2013年6月25日 星期二

[Software] 文件轉檔工具

好用的文件轉檔工具: Pandoc

常用指令: pandoc -s input.format -o output.format

這邊 format可以是 .tex, .html, .pdf, .doc, ...等等, 相當多, 注意: 這邊的 -s指的是 standalone而非 source

option 選項:

  • 可下 -m做數學轉換, 還有 --webtex或 --mathjax等可轉換, 但注意, 主要以 $...$排版, \begin{equation} 等環境並無法使用
  • --toc: table of content, 產生目錄 
  • -A: 加入內容於後, e.g. pandoc -s input.txt -A sample.html -o output.html, 則程式會將 input.txt轉成 html格式, 並在檔案後頭加入 sample.html的內容
  • -B: 加入內容於前
  • -c ./sample.css: 可加入 css的排版樣式

2013年6月5日 星期三

[Vim] Mac中 Vim 設定


  • 預設路徑
    • binary: /usr/bin
      support file: /usr/share/vim/vim73
      rc: ~/.vim/vimrc (若沒有, 請自己建)
  • 細節

    • 單一檔案的 plugin 應放在 ~/.vim/plugin下, e.g. a.vim
    • 其他 plugin一句底下的資料夾放置(例如: ctrlp)
      • ~/.vim/autoload/ctrlp/
      • ~/.vim/autoload/ctrlp/ctrlp.vim
      • ~/.vim/doc/ctrlp.txt
      • ~/.vim/plugin/ctrlp.vim
    • plugins/colorschemes/scripts 放在 ~/.vim下, not /usr/share/vim/vim73
  • 推薦 plugins:
    • a.vim: 在 header與 source file間切換
      • :A =>切換
      • :AT =>切換至新開的 tag page
      • :AS => split? 垂直分割
      • :AV => horizontal 分割
      • 不知為啥, 我覺得 :AS與 :AV 沒作用
  • Ref:

[Vim] vim 快攻


  • 重要參數
    • 可單獨操作
      • b  before
      • e  end
      • w  word
      • $  行末
      • 0  行頭
    • g global
    • c confirm
    • ! 強制
  • 移動
    • hjkl  分別是左下上右, 應該主要是右手食指上中指下
    • gg  檔案起始處
    • #shift-G  #代表行號, 沒輸入則是到檔案最後一行  
  • 檔案操作
    • :q     quit
    • :wq  write & quit
  • 文件編輯
    • i  insert
    • x  ...這不知道是啥
    • a  append, A  可在行末 append
    • d  delete, 可搭配參數, e.g: dw, d$, d0
    • p  paste
    • u  undo, U: 還原整行, ctrl-R為還原先前操作
    • o  open new line
    • %  找到配對的括號
    • dd 刪除行
  • 搜尋與取代類
    • /   向下搜尋, 找到後用 n跳至下一個, shift-N至上一個
    • ?  向上搜尋
    • 環境可設定 :set hls  highlight search, 便會有如 source Insight中 F8的功能啦, 要讓它消失則下 :noh   noHightLight
    • r   replace 單一字元
    • R  是同進入取代模式
    • c  change, 搭配參數用, e.g. cw: change word, 會取代掉 cursor所在的 word
    • :s  strike, 應該會是最常用的功能
      • s/old/new/g  將 old用 new取代, 若後面加 /g則為 global
      • s/old/new/gc  c是 confirm用
      • #,#s/old/new/gc  #是行號, 代表在這兩行之間的取代動作
  • 執行外部指令
    • :!script, script為 shell script, e.g. :!ls, 但有些動作還是不能操作, 剛試驗了一下, :!cd ~/Desktop, 再執行 :!pwd, 似乎並沒改變
    • :r fileName, 可將檔案 fileName的內容貼到目前 cursor處
  • 外掛類
    • a.vim
      • :a  switch between header/source code
    • ctag
    • auto complete
      • Ctrl-N

2013年6月1日 星期六

[Linux] GRUB2 開機順序

  • cd /etc/grub.d/ (開機順序存放在此資料夾, 以 prefix數字小到大的順序開機, 預設 linux為 10_linux, 優於 30_os-proper的 windows作業系統, 因此, 執行以下兩步驟, done!)
    • 30_os-proper 更名為 08_os-proper (mv ./30_os-proper ./08_os-proper)
    • sudo update-grub