简体   繁体   English

Qt qmake和DISTFILES

[英]Qt qmake and DISTFILES

So I am learning to program in OpenGL 3.3 and I am using qtcreator as my IDE with qmake as the compiler. 因此,我正在学习在OpenGL 3.3中进行编程,并使用qtcreator作为我的IDE,并使用qmake作为编译器。 Everything is fine except I have to read 2 files (fragmentshader.frag and vertexshader.vert) using ifstream. 一切都很好,除了我必须使用ifstream读取2个文件(fragmentshader.frag和vertexshader.vert)。 I have included those 2 files in the ".pro" like this: 我在“ .pro”中包含了这两个文件,如下所示:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp \
shaders.cpp

LIBS += -lGLEW -lglfw -lGL -lX11 -lpthread -lXrandr -lXi

DISTFILES += \
vertexshader.vert \
fragmentshader.frag

HEADERS += \
shaders.h

and in the code I try to directly read "vertexshader.vert" and "fragmentshader.frag". 在代码中,我尝试直接读取“ vertexshader.vert”和“ fragmentshader.frag”。

My question is: How do I include these files in my application without having to specify an absolute path? 我的问题是:如何在不指定绝对路径的情况下将这些文件包含在我的应用程序中?

I had the same problem, it comes from the fact Qt is running files from another directory (by default from the build one). 我有同样的问题,这是由于Qt正在从另一个目录(默认情况下是从构建目录)运行文件。

The Fix 修复

So you have two options: 因此,您有两种选择:

  • change the Working directory in Projects->Build & Run->Run to %{sourceDir} . Projects-> Build&Run-> Run中Working目录更改为%{sourceDir}
  • change the Build directory in Projects->Build & Run->Build to . Projects-> Build&Run-> Build中Build目录更改为. or leave it blank. 或将其留空。

Explanations 说明

  • The first option run your program (.exe on Windows) from the sourceDir, where your project sits, so path will remain the same relatively. 一个选项是从项目所在的sourceDir运行程序(在Windows上为.exe),因此路径相对保持不变。
  • The second option place all your build files (ie: Makefile, *.o and ".exe") in your project directory (they won't appear in the project view unless your Add them), I prefer this way because now your project directory contains everything related to it. 第二个选项将所有构建文件(即:Makefile,*。o和“ .exe”)放置在项目目录中(除非您添加它们,否则它们不会出现在项目视图中),我喜欢这种方式,因为现在您的项目目录包含与其相关的所有内容。

Choose the one you prefer the most, hope it helps. 选择最喜欢的一种,希望对您有所帮助。

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

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