日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Qt編程中qmake的使用詳解

系統(tǒng) 1798 0

首先說一下qt編程的步驟,然后再仔細(xì)說一下qmake的使用。我看書上的都是編寫好cpp文件后,分別執(zhí)行命令: qmake -project、qmake、make,然后執(zhí)行就可以了,但是要是我在一個(gè)文件夾下有多個(gè)cpp文件,qmake怎么識(shí)別?make生成的最后執(zhí)行文件的名,我怎么能隨心所欲的自己定?帶著疑問,找了網(wǎng)上的資料,不如所衣,然后嘗試著gcc編譯的思想竟然撞到了。

其實(shí)我感覺要要真正了解qmake的使用方法,直接在終端下輸入命令:qmake -help就可以了,我也是這樣做的,幫助內(nèi)容如下

    Usage: qmake [mode] [options] [files]

QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project

Mode:
  -project       Put qmake into project file generation mode
                 In this mode qmake interprets files as files to
                 be built,
                 defaults to *.c; *.ui; *.y; *.l; *.ts; *.xlf; *.qrc; *.h; *.hpp; *.hh; *.hxx; *.H; *.cpp; *.cc; *.cxx; *.C
                 Note: The created .pro file probably will 
                 need to be edited. For example add the QT variable to 
                 specify what modules are required.
  -makefile      Put qmake into makefile generation mode (default)
                 In this mode qmake interprets files as project files to
                 be processed, if skipped qmake will try to find a project
                 file in your current working directory

Warnings Options:
  -Wnone         Turn off all warnings; specific ones may be re-enabled by
                 later -W options
  -Wall          Turn on all warnings
  -Wparser       Turn on parser warnings
  -Wlogic        Turn on logic warnings (on by default)
  -Wdeprecated   Turn on deprecation warnings (on by default)

Options:
   * You can place any variable assignment in options and it will be     *
   * processed as if it was in [files]. These assignments will be parsed *
   * before [files].                                                     *
  -o file        Write output to file
  -d             Increase debug level
  -t templ       Overrides TEMPLATE as templ
  -tp prefix     Overrides TEMPLATE so that prefix is prefixed into the value
  -help          This help
  -v             Version information
  -after         All variable assignments after this will be
                 parsed after [files]
  -norecursive   Don't do a recursive search
  -recursive     Do a recursive search
  -set <prop> <value> Set persistent property
  -unset <prop>  Unset persistent property
  -query <prop>  Query persistent property. Show all if <prop> is empty.
  -cache file    Use file as cache           [makefile mode only]
  -spec spec     Use spec as QMAKESPEC       [makefile mode only]
  -nocache       Don't use a cache file      [makefile mode only]
  -nodepend      Don't generate dependencies [makefile mode only]
  -nomoc         Don't generate moc targets  [makefile mode only]
  -nopwd         Don't look for files in pwd [project mode only]
song@ubuntu:~/lianxi/qt$ clear

song@ubuntu:~/lianxi/qt$ qmake -help
Usage: qmake [mode] [options] [files]

QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project

Mode:
  -project       Put qmake into project file generation mode
                 In this mode qmake interprets files as files to
                 be built,
                 defaults to *.c; *.ui; *.y; *.l; *.ts; *.xlf; *.qrc; *.h; *.hpp; *.hh; *.hxx; *.H; *.cpp; *.cc; *.cxx; *.C
                 Note: The created .pro file probably will 
                 need to be edited. For example add the QT variable to 
                 specify what modules are required.
  -makefile      Put qmake into makefile generation mode (default)
                 In this mode qmake interprets files as project files to
                 be processed, if skipped qmake will try to find a project
                 file in your current working directory

Warnings Options:
  -Wnone         Turn off all warnings; specific ones may be re-enabled by
                 later -W options
  -Wall          Turn on all warnings
  -Wparser       Turn on parser warnings
  -Wlogic        Turn on logic warnings (on by default)
  -Wdeprecated   Turn on deprecation warnings (on by default)

Options:
   * You can place any variable assignment in options and it will be     *
   * processed as if it was in [files]. These assignments will be parsed *
   * before [files].                                                     *
  -o file        Write output to file
  -d             Increase debug level
  -t templ       Overrides TEMPLATE as templ
  -tp prefix     Overrides TEMPLATE so that prefix is prefixed into the value
  -help          This help
  -v             Version information
  -after         All variable assignments after this will be
                 parsed after [files]
  -norecursive   Don't do a recursive search
  -recursive     Do a recursive search
  -set <prop> <value> Set persistent property
  -unset <prop>  Unset persistent property
  -query <prop>  Query persistent property. Show all if <prop> is empty.
  -cache file    Use file as cache           [makefile mode only]
  -spec spec     Use spec as QMAKESPEC       [makefile mode only]
  -nocache       Don't use a cache file      [makefile mode only]
  -nodepend      Don't generate dependencies [makefile mode only]
  -nomoc         Don't generate moc targets  [makefile mode only]
  -nopwd         Don't look for files in pwd [project mode only]

  


qmake命令格式

qmake [mode] [options] [files]

mode選項(xiàng)

-project 生成.pro文件

-makefile 生成Makefile文件

options選項(xiàng)(這里介紹幾個(gè)常用的,其它的自己去翻譯上面,其實(shí)我也是剛學(xué),用到的時(shí)候再學(xué)習(xí)哈)

-o file 輸出文件名,比如qmake -project hello.cpp -o hello.pro,就會(huì)生成一個(gè)hello.pro文件,如果是qmake -project hello.cpp -o hello11.pro,就會(huì)生成一個(gè)hello11.pro文件

實(shí)驗(yàn)1

1、編寫代碼,命名為hello.cpp,如下

hello.cpp代碼如下

    #include<qapplication.h>
#include<qpushbutton.h>

int main(int argc,char *argv[])
{
    QApplication a(argc,argv);
    QPushButton hellobtn("Hello World!",0);
    hellobtn.resize(200,50);
    hellobtn.show();
    return a.exec();
}

  

2、 qmake -project (用于創(chuàng)建.pro文件,將所有的文件編譯成一個(gè)與平臺(tái)無關(guān)的工程文件)

可見默認(rèn)生成的文件名為 qt.pro

3、 qmake (讀取本身的Qt設(shè)置,生成與庫一致的相應(yīng)的Makefile)

4、 make (根據(jù)生成的Makefile,將文件編譯為二進(jìn)制可執(zhí)行程序)

Qt編程中qmake的使用詳解

可見生成了qt可執(zhí)行程序

5、執(zhí)行命令: ./qt

Qt編程中qmake的使用詳解

實(shí)驗(yàn)2

本實(shí)驗(yàn)中并沒有用到上面所講的方式,而是直接使用了默認(rèn)值,但是假設(shè)說該文件夾下有兩個(gè)cpp文件,如下圖

這時(shí)候再執(zhí)行命令:qmake -project會(huì)怎么樣呢?會(huì)出現(xiàn)下面的結(jié)果


有點(diǎn)意思,竟然不出錯(cuò),但是你知道它生成的qt.pro是哪個(gè)cpp文件的嗎?我不知道,加入這里我想對(duì)test.cpp操作,這時(shí)候就要按照上面的格式了。

1、qmake -project test.cpp -o test.pro

Qt編程中qmake的使用詳解

這時(shí)候生成了test.pro

2、qmake -makefile test.pro,這里生成test.pro的Makefile


3、make

4、執(zhí)行命令 ./test

Qt編程中qmake的使用詳解


Qt編程中qmake的使用詳解


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 化德县| 方山县| 武穴市| 布拖县| 宜昌市| 巧家县| 金堂县| 遂川县| 穆棱市| 乐业县| 开原市| 福贡县| 措勤县| 闽清县| 华蓥市| 黑河市| 衡南县| 湟源县| 长春市| 泸州市| 游戏| 浦东新区| 黔西县| 金塔县| 肃北| 灯塔市| 宝山区| 扶沟县| 西充县| 桐梓县| 清远市| 桐柏县| 休宁县| 诏安县| 克拉玛依市| 嘉兴市| 柞水县| 邻水| 涞水县| 建始县| 铁岭县|