在 Qt 中使用 .pri 文件 [英] Using .pri files in Qt

查看:75
本文介绍了在 Qt 中使用 .pri 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这个问题的后续

所以,我的问题是:

  • .pri 文件的一般格式是什么?
  • 为什么上述解决方案不起作用?

解决方案

从你的截图来看,我猜测 QtCreator 没有找到 .pri 文件中列出的头文件.如果您的 .pri 文件位于与 .pro 文件不同的目录中(这里似乎是这种情况),Qt 会在 .pri 文件所在的目录中查找 .pri 文件中列出的文件(而不是 .pri 文件).pro 文件),并且将从该目录解析任何相对路径.

当找不到文件时,QtCreator 会默默地忽略它,并且不会将其添加到项目视图中的文件夹中.例如,如果您在 include.pri 文件中使用 line.h、circle.h 和 bezier.h 的完整路径,则一旦保存文件,您就会看到它们出现在项目视图中.现在的关键只是找出相对于 .pri 文件指向这些文件的适当相对路径是什么.

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:

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.

这篇关于在 Qt 中使用 .pri 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆