• Qt pro pri 文件学习1


    pro文件是一个工程文件,就是可以独立执行的项目的最高首领;pri文件比pro文件简单的多,单纯的为了编者逻辑上的区分或者思路的厘清,不具备单独执行的条件。一般pri文件包含:

    HEADERS += \
        page/systemsetup.h \

    SOURCES += \
        page/systemsetup.cpp \
     也就是其头文件和源文件;其实用pri文件的地方完全可以用pro文件代替,只不过前者简单实用;

    --------------------------------------------------------------------------------------------------------------------

    This is a followup to this question How to create a subdirectory for a project in qt-creator?, where the first answer didn't work for me.

    I resolved it by manually writing every file into the main .pro file, which is not that much harder, but I still wonder - how exactly .pri files work, and why the solution linked above didn't add the folders, but only the .pri files, so it looked like this in Qt creator:

    Qt creator screenshot

    So, my questions are:

    • What is the general format of the .pri files?
    • Why the solution above doesn't work?

    My guess from looking at your screenshot is that QtCreator doesn't find the header files listed in the .pri file. If your .pri file is located in a different directory than your .pro file (which seems to be the case here), Qt looks for the files listed in the .pri file in the same directory as the .pri file (not the .pro file), and any relative path will be resolved from that directory.

    When a file can't be found, QtCreator silently ignores it and simply doesn't add it to the folder in the projects view. If, for example, you used the full path for line.h, circle.h and bezier.h in your include.pri file, as soon as you save the file, you'll see them appear in the projects view. The key now is simply to figure out what is the appropriate relative path pointing to those files relative to the .pri file.

    The format of the .pri files is exactly the same as the format of the .pro files. The main difference is one of intent; a .pro is what most people would expect to run qmake on directly, while a .pri is to be included by a .pro. When you instruct qmake to include another file, it just processes the commands in that file as if it were in the current file.

    The last time I looked at Qt Creator, it would do additional parsing and recognize that .pri files were separate, and list any headers/sources/ui/rc/pri files from that file specifically as a subdirectory, much like you see the include.pri files listed in the screenshot of this question.

    Extracted from Qt 4.5: Managing Projects:

    The .pri file contains the list of source files, header files, .ui files, and .qrc files in the project.

    For more about these files and their OSs:

    • A .vcproj file containing Windows-specific settings and listing the files in the project.
    • A .pro file containing Unix and/or Mac OS X specific settings.
    • A .pri file (a qmake include file) listing the files in the project.
    Managing Projects
    Creating New Qt Projects
    
    Once you have installed the add-in, Visual Studio's New Project dialog will contain a Qt Projects folder with the following project templates:
    
        Qt Application: A simple Qt GUI Application with one form.
        Qt Console Application: A basic Qt console application.
        Qt Library: A basic Qt-based dynamic library.
        Qt4 Designer Plugin: A Qt Designer custom widget plugin.
        ActiveQt Server: A simple ActiveX server.
    
    If you have a Qt for Windows CE license, two additional project types are available:
    
        Qt WindowsCE Application: A simple Qt GUI Application for Windows CE with one form.
        Qt WindowsCE Library: A basic Qt-based dynamic library for Windows CE.
    
    Each Qt project provides a wizard that allows you to specify the Qt modules required for your project. For some projects, the wizard will also generate a skeleton class that you can use to get started.
    
    If you have used the installer for the binary version of Qt, you are now ready to write Qt code and build your projects. Alternatively, if you have built Qt from source, then you must tell Visual Studio where to find Qt. This step is further explained in the Basic Qt Version Management section.
    Modifying Project Properties
    
    Qt related project properties can be modified by opening the Qt Project Settings dialog. To display this dialog, select the respective Qt project in the solution explorer and select Qt|Qt Project Settings.
    
    Screenshot of the property browser when selecting a Qt project
    
    The following Qt project settings can be changed:
    
    Property	Description
    Version	The Qt version to use for this project (see Basic Qt Version Management).
    MocDirectory	The directory (relative to the project) where the generated moc files are put. This directory must include the $(ConfigurationName) variable, to ensure that the moc files for different configurations (e.g., debug or release) do not collide.
    MocOptions	Additional command line options for the moc build step.
    UicDirectory	The directory (relative to the project) where the uic generated header files are put.
    RccDirectory	The directory (relative to the project) where the rcc generated source files are put.
    
    When a Qt project is created, these properties are initialized to default values based on the last entered information found in the the Qt|Qt Project Settings dialog.
    Basic Qt Version Management
    
    The Visual Studio Add-in offers its own simple Qt version management, enabling you to use multiple versions of Qt 4 in parallel, e.g., Qt 4.5.0 and 4.5.1. When you install the add-in, the information about Qt versions is added to the user registry hive. So, another user will have to add a new Qt version since no default version will be set.
    
    To add or remove Qt versions, click Qt|Configure Qt Versions and select the Qt Versions page. Click Add, then enter a name for the Qt version and the path to Qt's root directory, for example, C:\\Qt\\4.5.0". The first added Qt version is automatically the default version which will be used when creating new projects or importing a project from a .pro file. The default versions for Qt Windows or Windows CE projects can be changed using the combo boxes located under the Qt Builds list.
    
    Screenshot of Qt versions configuration dialog
    
    To specify which Qt version a project should use, select the project node of a Qt project (e.g., "Project1") in the Solution Explorer, and set its Version property using the Qt Project Settings.
    
    Changing the Qt version for all projects in the solution can be done by invoking the context menu of the solution and activating the Change Solutions' Qt Version item. You can then select your desired Qt version in the dialog listing all available Qt versions.
    
    Note: When you set a Qt version for the solution, this version becomes the default version if you add new projects to the solution.
    
    Using the Qt Visual Studio Add-in does not require a globally set Qt environment variable. The Add-in will always overwrite the existing global Qt environment variable.
    
    Note: If the build of your Qt projects fails with the error message The following environment variables were not found: $(QTDIR), then the project is probably referencing an invalid Qt build. This can happen after uninstalling an old Qt version. To correct this, change the Qt version of your project to a valid one.
    Changing The Target Platform of Your Project
    
    If you are developing on the Windows CE platform, Visual Studio Add-in enables you to switch between Windows and Windows CE easily. It is possible to create a standard Windows project, develop and test your application on your desktop PC, then later convert it into a Qt on Windows CE version.
    
    To switch between platforms choose the appropriate Qt version in the Version property using the property browser, as described above.
    Importing and Exporting Projects
    
    Qt and Visual Studio use different file formats to save projects. If you build your application on multiple platforms, you probably already use Qt .pro files with qmake; otherwise, you might use .vcproj files and Visual Studio to build your project, usually convenient for Windows- only development.
    
    Qt's Visual Studio add-in provides a way to combine both approaches - you do not have to manually maintain .pro files and .vcproj files in parallel. You start by creating a .vcproj file as usual. When you want a qmake .pro file, select Qt|Create Basic .pro File to generate a .pro file where you can store Unix and/or Mac OS X specific settings.
    
    Screenshot of export dialog
    
    If you have multiple Qt projects in one Visual Studio solution, the basic .pro file generator can create a master .pro file of type subdirs that includes all of the projects.
    
    The generated .pro file is not meant to be a complete file, but a simple starting point for porting to other platforms. Having said, these files should be sufficient for compiling the skeleton projects created by the predefined Qt project wizards. The .pro file includes a .pri file.
    
    The .pri file contains the list of source files, header files, .ui files, and .qrc files in the project. To generate the .pri file, select Qt|Export Project to .pri File. Whenever you add or remove a file from the Visual Studio project file, you must regenerate the .pri file to ensure that the application can still be build on other platforms.
    
    Also, ensure that the included .pri file in the .pro file points to the right file. If you saved the .pri file in the suggested path and name, this should be correct.
    
    Developers on platforms other than Windows can add or remove files to the project by editing the .pri file. When this happens, Windows developers must select Qt|Import .pri File to Project to bring the Visual Studio project file in sync with the .pri file.
    
    If your project contains platform-specific source files, these files should be listed in the .pro file so that they are not overwritten by the Visual Studio Add-in.
    
    In summary, a cross-platform Qt project consists of the following files:
    
        A .vcproj file containing Windows-specific settings and listing the files in the project.
        A .pro file containing Unix and/or Mac OS X specific settings.
        A .pri file (a qmake include file) listing the files in the project.
    
    If you already have a .pro file but not a .vcproj file, select Qt|Open Qt Project File (.pro)... to convert your .pro file to a .vcproj file. Be aware that the generated .vcproj only contains Windows-specific settings. Also, there is no way to convert a .vcproj file back to a .pro file format, apart from the basic .pro mechanism described above.
    

  • 相关阅读:
    C算法编程题系列
    C算法编程题(七)购物
    C算法编程题(六)串的处理
    C算法编程题(五)“E”的变换
    C算法编程题(四)上三角
    C算法编程题(三)画表格
    C算法编程题(二)正螺旋
    C算法编程题(一)扑克牌发牌
    我的编程开始(C)
    T-Sql学习系列完结
  • 原文地址:https://www.cnblogs.com/Cmpl/p/2143113.html
Copyright © 2020-2023  润新知