在 Qt 中使用 .pri 文件

编程入门 行业动态 更新时间:2024-10-25 00:25:59
本文介绍了在 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 文件

本文发布于:2023-10-25 22:20:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528271.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Qt   pri

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!