日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Qt文档阅读笔记-qmake入门指南

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt文档阅读笔记-qmake入门指南 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

?

qmake的作用

簡單的小例子

跨平臺的例子


?

qmake的作用


1.生成Makefile文件;
2.生成moc和uic文件;
3.用vs打開Qt時無需要改變pro文件就能能夠生成項目;

在Linux中qmake的主要目的是簡化程序員編寫Makefile;

?

簡單的小例子

手寫一個簡單的pro文件,用再用qmake下;

首先寫一個小例子:

包含4個文件:

hello.h、hello.cpp、main.cpp、hello.pro

源碼如下:

hello.h

#include <iostream> using namespace std;class Hello{ public:Hello();void print(); };

hello.cpp

#include "hello.h"Hello::Hello(){cout << "Hello construction called!" << endl; } void Hello::print(){cout << "Hello::print called!" << endl; }

main.cpp

#include "hello.h"int main(){Hello *hello = new Hello;hello->print();delete hello;return 0; }

hello.pro

TARGET = helloworldCONFIG += debugHEADERS += hello.hSOURCES += hello.cpp \main.cpp

?

TARGET一般與pro文件同名,但后綴名應平臺而異,如exe是Windows平臺上的,無后綴是Unix上的,如果想設置一個其他的名字,可以在此設置其他名稱;

使用這條命令生成Makefile
qmake -o Makefile hello.pro

Linux的操作如下圖所示:


隨后使用make即可
在VS中想上次vc的文件要使用下面這條命令:
qmake -tp vc hello.pro?-spec win32-msvc2012

Windows的操作如下圖:

設置好,vs,如果沒輸出,注意設置控制臺輸入,如下圖所示:

運行截圖如下:

?

跨平臺的例子

存在下面幾個文件:

hello.cpp、hello.h、hellounix.cpp、hellounix.h、hellowin.cpp、hellowin.h、main.cpp、hello.pro

具體內容如下:

hello.h

#include <iostream> using namespace std;class Hello{ public:Hello();void print(); };

hello.cpp

#include "hello.h"Hello::Hello(){cout << "Hello construction called!" << endl; } void Hello::print(){cout << "Hello::print called!" << endl; }

hellounix.h

#include <iostream> using namespace std;class UnixHello{ public:UnixHello();void print(); };

hellounix.cpp

#include "hellounix.h"UnixHello::UnixHello(){cout << "UnixHello construction called!" << endl; }void UnixHello::print(){cout << "UnixHello construction called!" << endl; }

hellowin.h

#include <iostream> using namespace std;class WinHello{ public:WinHello();void print(); };

hellowin.cpp

#include "hellowin.h"WinHello::WinHello(){cout << "WinHello contraction is called!" << endl; }void WinHello::print(){cout << "WinHello print() called!" << endl; }

main.cpp

#include "hello.h" #include <QApplication>#ifdef Q_OS_WIN32 #include "hellowin.h" #else #include "hellounix.h" #endifint main(){Hello *hello = new Hello;hello->print();delete hello;#ifdef Q_OS_WIN32WinHello *winHello = new WinHello;winHello->print(); #elseUnixHello *unixHello = new UnixHello;unixHello->print(); #endifreturn 0; }

hello.pro

TARGET = helloworldCONFIG += debugHEADERS += hello.hSOURCES += hello.cpp \main.cppwin32 {HEADERS += hellowin.hSOURCES += hellowin.cpp } unix {HEADERS += hellounix.hSOURCES += hellounix.cpp }

在Linux上運行截圖如下:

在Windows上運行截圖如下:

?


如果想調試程序可以使用CONFIG這個變量,標記程序為debug版本
如下所示:

源碼如下:

CONFIG += debugHEADERS += hello.hSOURCES += hello.cppSOURCES += main.cpp

如果想調試程序可以使用CONFIG這個變量,標記程序為debug版本
如下所示:

win32 {SOURCES += hellowin.cpp}

使用win32與unix來決定跨平臺的特性【前提是各個平臺的代碼分離】
如下所示:

CONFIG += debugHEADERS += hello.hSOURCES += hello.cppSOURCES += main.cppwin32 {SOURCES += hellowin.cpp}unix {SOURCES += hellounix.cpp}

exists命令,當缺少文件的時候會停止qmake

win32 {debug {CONFIG += console}}

后面這個是在Windows上,想調出控制臺的時候(qDebug能打印),需要做的事情

總結

以上是生活随笔為你收集整理的Qt文档阅读笔记-qmake入门指南的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。