MyException - 我的异常网
当前位置:我的异常网» 编程 » 关于QT的pro资料编写及英文文档

关于QT的pro资料编写及英文文档

www.MyException.Cn  网友分享于:2013-10-09  浏览:36次
关于QT的pro文件编写及英文文档

最近打算利用QT+OpenCV来学习图像处理,但是在编写一个简单的入门例程时遇到了编译问题(如下图),下面就来整理一下有关pro文件的写法。



.pro文件的写法如下:


1. 注释
从“#”开始,到这一行结束。

2.模板变量告诉qmake为这个应用程序生成哪种makefile。下面是可供使用的选择:
TEMPLATE = app
A> app -建立一个应用程序的makefile。这是默认值,所以如果模板没有被指定,这个将被使用。
B> lib - 建立一个库的makefile。
C> vcapp - 建立一个应用程序的VisualStudio项目文件。
D> vclib - 建立一个库的VisualStudio项目文件。
E> subdirs -这是一个特殊的模板,它可以创建一个能够进入特定目录并且为一个项目文件生成makefile并且为它调用make的makefile。


#指定生成的应用程序放置的目录
DESTDIR += ../bin

#指定生成的应用程序名
TARGET = pksystem

#配置信息
CONFIG用来告诉qmake关于应用程序的配置信息。

    CONFIG+= qt warn_on release

在这里使用“+=”,是因为我们添加我们的配置选项到任何一个已经存在中。这样做比使用“=”那样替换已经指定的所有选项是更安全的。
A> qt部分告诉qmake这个应用程序是使用Qt来连编的。这也就是说qmake在连接和为编译添加所需的包含路径的时候会考虑到Qt库的。
B> warn_on部分告诉qmake要把编译器设置为输出警告信息的。
C> release部分告诉qmake应用程序必须被连编为一个发布的应用程序。在开发过程中,程序员也可以使用debug来替换release


#指定uic命令将.ui文件转化成ui_*.h文件的存放的目录
UI_DIR += forms

#指定rcc命令将.qrc文件转换成qrc_*.h文件的存放目录
RCC_DIR += ../tmp

#指定moc命令将含Q_OBJECT的头文件转换成标准.h文件的存放目录
MOC_DIR += ../tmp

#指定目标文件(obj)的存放目录
OBJECTS_DIR += ../tmp

#程序编译时依赖的相关路径
DEPENDPATH += . forms include qrc sources

#头文件包含路径
INCLUDEPATH += .

#qmake时产生的信息,【$${a}读取变量a的字符串】,【$$(PATH)读取环境变量PATH】
#message($$(PATH))

#源文件编码方式
CODECFORSRC = GBK

#工程中包含的头文件
HEADERS += include/painter.h
#工程中包含的.ui设计文件
FORMS += forms/painter.ui
#工程中包含的源文件
SOURCES += sources/main.cpp sources/painter.cpp
#工程中包含的资源文件
RESOURCES += qrc/painter.qrc

 

LIBS += -L folderPath  //引入的lib文件的路径  -L:引入路径

Release:LIBS += -L folderPath // release 版引入的lib文件路径

Debug:LIBS += -L folderPath // Debug 版引入的lib 文件路径

DEFINES += XX_XX_XXX  //定义编译选项,在.h文件中就可以使用 :#ifdefine xx_xx_xxx

RC_FILE = xxx.icns

7. 平台相关性处理
我们在这里需要做的是根据qmake所运行的平台来使用相应的作用域来进行处理。为Windows平台添加的依赖平台的文件的简单的作用域看起来就像这样:

win32 {
SOURCES += hello_win.cpp
}
====================================================================================================================
当你已经创建好你的项目文件,生成Makefile就很容易了,你所要做的就是先到你所生成的项目文件那里然后输入:

Makefile可以像这样由“.pro”文件生成:

    qmake -oMakefile hello.pro

对于VisualStudio的用户,qmake也可以生成“.dsp”文件,例如:

    qmake -tvcapp -o hello.dsp hello.pro

 

++++++++++++++++++++++++一个PRO文件实例++++++++++++++++++++++++++++++++++++++++

TEMPLATE = app     #模块配置
LANGUAGE = C++   #C++语言

CONFIG += qt warn_on debug release

#引入的lib文件,用于引入动态链接库
LIBS += qaxcontainer.lib

#头文件包含路径
INCLUDEPATH += ../../qtcompnent/qtchklisten/inc ../../qtcompnent/qtclearfile/inc ../../validator/inc/validerrcode ../../qtcompnent/qtdir/inc ../inc ../../utillib/inc/xmlapi ../../utillib/inc/util ../../xercesc ../../qtcompnent/qteditor/inc ../../qtcompnent/qtfunreview/inc ../../qtcompnent/qttable/inc ../../qtcompnent/qtversion/inc ../../qtcompnent/qtini/inc ../../icdtool/icdservices/inc ../../icdtool/dataset/inc ../../icdtool/doi/inc ../../icdtool/reportcontrol/inc ../../icdtool/GSEconctrol/inc ../../icdtool/inputs/inc ../../icdtool/SMVconctrol/inc ../../icdtool/logcontrol/inc ../../scdpreview/inc/scdpreviewtoollib ../../scdpreview/form ../../icdtool/sclcontrol/inc ../../icdtool/log/inc ../../icdtool/settingcontrol/inc ../../qtcompnent/qteditor/inc ../../qtcompnent/qttreeview/inc ../../qtcompnent/qttabwidget/inc ../../communication/inc ../../qtcompnent/qtabout/inc ../iedmanage/inc ../ldmanage/inc ../foriecrun/inc ../../qtcompnent/validset/inc

#工程中包含的头文件
HEADERS += ../inc/exportstable.h /
 ../inc/maintabwidget.h /
 ../inc/outputtab.h /
 ../inc/strutil.h /
 ../inc/treeeditview.h /
 ../inc/MainForm.h /
 ../inc/recenfileini.h /
 ../inc/ExportCIDFunction.h

#工程中包含的源文件
SOURCES += ../src/main.cpp /
 ../src/exportstable.cpp /
 ../src/maintabwidget.cpp /
 ../src/outputtab.cpp /
 ../src/treeeditview.cpp /
 ../src/MainForm.cpp /
 ../src/recenfileini.cpp /
 ../src/ExportCIDFunction.cpp

#工程中包含的.ui设计文件
FORMS = ../form/scdmainform.ui /
 ../form/exportiedform.ui /
 ../form/Exportsedform.ui /
 ../form/Importsedform.ui /
 ../form/formiminputs.ui

#图像文件

IMAGES = images/substation.png /
 images/communication.png /
 images/autocom.png /
 images/reportcfg.png /
 images/comcfg.png /
 images/filetrans.png /
 images/review.png /
 images/setting.png

#工程中包含的资源文件
RESOURCES   = Scintilla.qrc

#CONFIG -= release
CONFIG -= debug


RC_FILE = scdtool.rc

 
BINLIB = ../../bin ../../xercesc/lib

UI_HEADERS_DIR = ../inc  # .ui文件转会为**.h   存放的目录
UI_SOURCES_DIR = ../src  # .ui文件转会为**.cpp 存放的目录
QMAKE_LIBDIR = $${BINLIB}

release {
TARGET = scdtool       #指定生成的应用程序名
OBJECTS_DIR = ../../obj/scdtool/release #指定目标文件(obj)的存放目录
}
debug {
TARGET = scdtool_d     #指定生成的应用程序名
OBJECTS_DIR = ../../obj/scdtool/debug #指定目标文件(obj)的存放目录
}

MOC_DIR = $${OBJECTS_DIR}
DESTDIR = ../../bin    #指定生成的应用程序放置的目录

——————————————————————————————————————————



qmake Tutorial

This tutorial teaches you how to use qmake. We recommend that you read the qmake user guide after completing this tutorial.

Starting off Simple

Let's assume that you have just finished a basic implementation of your application, and you have created the following files:

  • hello.cpp
  • hello.h
  • main.cpp

You will find these files in the examples/qmake/tutorial directory of the Qt distribution. The only other thing you know about the setup of the application is that it's written in Qt. First, using your favorite plain text editor, create a file called hello.pro in examples/qmake/tutorial. The first thing you need to do is add the lines that tell qmake about the source and header files that are part of your development project.

We'll add the source files to the project file first. To do this you need to use the SOURCES variable. Just start a new line with SOURCES += and put hello.cpp after it. You should have something like this:

 SOURCES += hello.cpp

We repeat this for each source file in the project, until we end up with the following:

 SOURCES += hello.cpp
 SOURCES += main.cpp

If you prefer to use a Make-like syntax, with all the files listed in one go you can use the newline escaping like this:

 SOURCES = hello.cpp \
           main.cpp

Now that the source files are listed in the project file, the header files must be added. These are added in exactly the same way as source files, except that the variable name we use is HEADERS.

Once you have done this, your project file should look something like this:

 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp

The target name is set automatically; it is the same as the project file, but with the suffix appropriate to the platform. For example, if the project file is called hello.pro, the target will be hello.exe on Windows and hello on Unix. If you want to use a different name you can set it in the project file:

 TARGET = helloworld

The final step is to set the CONFIG variable. Since this is a Qt application, we need to put qt on the CONFIG line so thatqmake will add the relevant libraries to be linked against and ensure that build lines for moc and uic are included in the generated Makefile.

The finished project file should look like this:

 CONFIG += qt
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp

You can now use qmake to generate a Makefile for your application. On the command line, in your project's directory, type the following:

 qmake -o Makefile hello.pro

Then type make or nmake depending on the compiler you use.

For Visual Studio users, qmake can also generate .dsp or .vcproj files, for example:

 qmake -tp vc hello.pro

Making an Application Debuggable

The release version of an application doesn't contain any debugging symbols or other debugging information. During development it is useful to produce a debugging version of the application that has the relevant information. This is easily achieved by adding debug to the CONFIG variable in the project file.

For example:

 CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp

Use qmake as before to generate a Makefile and you will be able to obtain useful information about your application when running it in a debugging environment.

Adding Platform-Specific Source Files

After a few hours of coding, you might have made a start on the platform-specific part of your application, and decided to keep the platform-dependent code separate. So you now have two new files to include into your project file:hellowin.cpp and hellounix.cpp. We can't just add these to the SOURCES variable since this will put both files in the Makefile. So, what we need to do here is to use a scope which will be processed depending on which platform qmake is run on.

A simple scope that will add in the platform-dependent file for Windows looks like this:

 win32 {
     SOURCES += hellowin.cpp
 }

So if qmake is run on Windows, it will add hellowin.cpp to the list of source files. If qmake is run on any other platform, it will simply ignore it. Now all that is left to be done is to create a scope for the Unix-specific file.

When you have done that, your project file should now look something like this:

 CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp
 win32 {
     SOURCES += hellowin.cpp
 }
 unix {
     SOURCES += hellounix.cpp
 }

Use qmake as before to generate a Makefile.

Stopping qmake If a File Doesn't Exist

You may not want to create a Makefile if a certain file doesn't exist. We can check if a file exists by using the exists() function. We can stop qmake from processing by using the error() function. This works in the same way as scopes do. Simply replace the scope condition with the function. A check for a main.cpp file looks like this:

 !exists( main.cpp ) {
     error( "No main.cpp file found" )
 }

The ! symbol is used to negate the test; i.e. exists( main.cpp ) is true if the file exists, and !exists( main.cpp )is true if the file doesn't exist.

 CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp
 win32 {
     SOURCES += hellowin.cpp
 }
 unix {
     SOURCES += hellounix.cpp
 }
 !exists( main.cpp ) {
     error( "No main.cpp file found" )
 }

Use qmake as before to generate a makefile. If you rename main.cpp temporarily, you will see the message and qmakewill stop processing.

Checking for More than One Condition

Suppose you use Windows and you want to be able to see statement output with qDebug() when you run your application on the command line. Unless you build your application with the appropriate console setting, you won't see the output. We can easily put console on the CONFIG line so that on Windows the makefile will have this setting. However, let's say that we only want to add the CONFIG line if we are running on Windows and when debug is already on the CONFIG line. This requires using two nested scopes; just create one scope, then create the other inside it. Put the settings to be processed inside the last scope, like this:

 win32 {
     debug {
         CONFIG += console
     }
 }

Nested scopes can be joined together using colons, so the final project file looks like this:

 CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp
 win32 {
     SOURCES += hellowin.cpp
 }
 unix {
     SOURCES += hellounix.cpp
 }
 !exists( main.cpp ) {
     error( "No main.cpp file found" )
 }
 win32:debug {
     CONFIG += console
 }

That's it! You have now completed the tutorial for qmake, and are ready to write project files for your development projects


文章评论

10个帮程序员减压放松的网站
10个帮程序员减压放松的网站
为什么程序员都是夜猫子
为什么程序员都是夜猫子
程序员眼里IE浏览器是什么样的
程序员眼里IE浏览器是什么样的
如何区分一个程序员是“老手“还是“新手“?
如何区分一个程序员是“老手“还是“新手“?
中美印日四国程序员比较
中美印日四国程序员比较
程序员和编码员之间的区别
程序员和编码员之间的区别
做程序猿的老婆应该注意的一些事情
做程序猿的老婆应该注意的一些事情
代码女神横空出世
代码女神横空出世
不懂技术不要对懂技术的人说这很容易实现
不懂技术不要对懂技术的人说这很容易实现
60个开发者不容错过的免费资源库
60个开发者不容错过的免费资源库
鲜为人知的编程真相
鲜为人知的编程真相
Web开发者需具备的8个好习惯
Web开发者需具备的8个好习惯
要嫁就嫁程序猿—钱多话少死的早
要嫁就嫁程序猿—钱多话少死的早
旅行,写作,编程
旅行,写作,编程
5款最佳正则表达式编辑调试器
5款最佳正则表达式编辑调试器
Web开发人员为什么越来越懒了?
Web开发人员为什么越来越懒了?
老程序员的下场
老程序员的下场
写给自己也写给你 自己到底该何去何从
写给自己也写给你 自己到底该何去何从
Java 与 .NET 的平台发展之争
Java 与 .NET 的平台发展之争
当下全球最炙手可热的八位少年创业者
当下全球最炙手可热的八位少年创业者
每天工作4小时的程序员
每天工作4小时的程序员
我是如何打败拖延症的
我是如何打败拖延症的
一个程序员的时间管理
一个程序员的时间管理
科技史上最臭名昭著的13大罪犯
科技史上最臭名昭著的13大罪犯
 程序员的样子
程序员的样子
总结2014中国互联网十大段子
总结2014中国互联网十大段子
老美怎么看待阿里赴美上市
老美怎么看待阿里赴美上市
那些争议最大的编程观点
那些争议最大的编程观点
亲爱的项目经理,我恨你
亲爱的项目经理,我恨你
我跳槽是因为他们的显示器更大
我跳槽是因为他们的显示器更大
“肮脏的”IT工作排行榜
“肮脏的”IT工作排行榜
程序猿的崛起——Growth Hacker
程序猿的崛起——Growth Hacker
聊聊HTTPS和SSL/TLS协议
聊聊HTTPS和SSL/TLS协议
10个调试和排错的小建议
10个调试和排错的小建议
程序员最害怕的5件事 你中招了吗?
程序员最害怕的5件事 你中招了吗?
为啥Android手机总会越用越慢?
为啥Android手机总会越用越慢?
程序员的一天:一寸光阴一寸金
程序员的一天:一寸光阴一寸金
“懒”出效率是程序员的美德
“懒”出效率是程序员的美德
程序员的鄙视链
程序员的鄙视链
程序员周末都喜欢做什么?
程序员周末都喜欢做什么?
如何成为一名黑客
如何成为一名黑客
程序员必看的十大电影
程序员必看的十大电影
Java程序员必看电影
Java程序员必看电影
初级 vs 高级开发者 哪个性价比更高?
初级 vs 高级开发者 哪个性价比更高?
程序员应该关注的一些事儿
程序员应该关注的一些事儿
软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有