简体   繁体   English

Qt Creator IDE的构建目录

[英]Build directory for Qt Creator IDE

I am trying to populate a QTableview with some data. 我试图用一些数据填充QTableview When developing under Qt Creator, data is read from build directory. 在Qt Creator下进行开发时,将从构建目录读取数据。 Running the program each time, the QTableview keeps getting repopulated with previous data. 每次运行该程序时, QTableview不断填充以前的数据。

If I manually change the build directory each time before run, doesn't happen. 如果每次运行前我都手动更改构建目录,则不会发生。 But how do I solve the problem without manually changing the build directory every time I want a fresh run? 但是,如何在不希望每次重新运行时都手动更改构建目录的情况下解决问题呢?

In your project directory there is a file name ProjectName.pro.user . 在您的项目目录中,有一个文件名ProjectName.pro.user

This file creating when you configure your project. 该文件在您配置项目时创建。 it's XML file. 这是XML文件。

you can find this line on *.user files: 您可以在*.user文件中找到此行:

<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/probook/Documents/Qt/testProject/Build/Windows/Debug</value>

This line define build directory address for debug. 此行定义用于调试的构建目录地址。 there is a same line for Release and Profile in that file. 该文件中的“发布”和“配置文件”有同一行。

You can also use Qt creator to define(customize) relative directory build: goto Qt creator, Tools , Options... , Build & Run , General , Default build directory . 您还可以使用Qt创建者来定义(自定义)相对目录构建:转到Qt创建者, ToolsOptions...Build & RunGeneralDefault build directory 屏幕截图

More info: 更多信息:

Qt Creator stores user-specific project settings in a .pro.user file. Qt Creator将用户特定的项目设置存储在.pro.user文件中。 You can share these settings between several projects as a .pro.shared file. 您可以在多个项目之间以.pro.shared文件共享这些设置。 It has the same XML structure as a .pro.user file, but only contains the settings to share. 它具有与.pro.user文件相同的XML结构,但仅包含要共享的设置。

Based on comment, issue seems to be data which gets saved to build directory. 根据评论,问题似乎是已保存到构建目录中的数据。 And solution would be to remove it before running the application. 解决方案是在运行应用程序之前将其删除。

You can add Custom Process Step , either under Projects - Build Settings - Build Steps , or under Projects - Run Settings - Deployment , and just delete the desired data files. 您可以在“ 项目”-“构建设置”-“构建步骤”下 ,或者在“ 项目”-“运行设置”-“部署 下添加“ 自定义过程步骤 ,然后删除所需的数据文件。 Exact command depends on operating system. 确切的命令取决于操作系统。

An alternative might be to add a command line switch, something like --development-erase-saved-data , to the application itself, and erase the files (or just not read them, or whatever). 一种替代方法是在应用程序本身中添加一个命令行开关(如--development-erase-saved-data ,然后擦除文件(或只是不读取它们,或进行其他操作)。 Then add that command line switch to Projects - Run Settings - Run Steps - Command Line Arguments for desired build configurations. 然后将该命令行开关添加到“ 项目”-“运行设置”-“运行步骤”-“命令行参数”以获取所需的构建配置。

Adding support for this in the application itself is easier to maintain, and is almost automatically cross-platform. 在应用程序本身中添加对此的支持更容易维护,并且几乎可以自动跨平台。 However, it might be a feature you don't want in the application, though in that case you might only enable it for Debug builds (with #ifdef ). 但是,它可能是您不希望在应用程序中使用的功能,尽管在这种情况下,您可能仅将其启用用于Debug构建(使用#ifdef )。


As a side note, saving data to executable directory is not a good idea these days. 顺便提一句,将数据保存到可执行文件目录已不是一个好主意。 You might want to save it for example to location returned by 您可能想要将其保存到例如由返回的位置

QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)

(See here for more info.) (有关更多信息,请参见此处 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM