如何在Qt Creator中为不同的构建设置定义常量
How to define constants in Qt Creator for different Build Settings?
我正在开发与服务器连接的Qt应用程序。我有一个生产服务器和一个预生产服务器,所以它将是伟大的,能够改变URL的应用程序使用基于构建。
所以,总结一下,我需要应用程序像这样运行: 调试配置//somewhere in a .cpp file
QString url = BASE_URL;
// url now is, for example, "preproduction_server.com"
发布配置
//in the same .cpp file
QString url = BASE_URL;
// url now is, for example, "production_server.com"
任何想法?我应该在.pro文件中定义变量并使用它们吗?将它们定义为环境变量?
最后我用QT_NO_DEBUG
这是我的代码现在的样子
#ifdef QT_NO_DEBUG
#define BASE_URL "production_server.com"
#else
#define BASE_URL "preproduction_server.com"
#endif
NDEBUG
应该由qmake为发布版本定义,因此您可以使用:
#ifdef NDEBUG
#define BASE_URL "production_server.com"
#else
#define BASE_URL "preproduction_server.com"
#endif
相关文章:
- docker 构建失败:无法设置环境变量
- 如何在提升构建中设置环境变量以进行提升单元测试框架?
- 如何使用cmake设置OpenCV以启用动态和静态构建
- 如何设置 CMake 来构建包含路径包含的代码,如 #include < libdir/lib>?
- 如何为特定的构建风格设置 cpp 文件夹
- 设置用G 构建的二进制版本的任何方法
- 如何最好地为 Visual Studio 2017 构建的 CMake C++ 项目设置输出目录
- Delphi / C 构建器 - 在TDBGrid中设置活动 /选择的行颜色
- 我正在尝试在Eclipse中构建一个C 项目,但是即使在使用MINGW路径设置路径变量之后,也会获得构建错误
- 在为C 设置NetBean时,它显示了未连接的构建主机
- 在C 中以通用方式构建对象,设置字段并返回对象
- 在C++构建器5中设置默认浏览器
- Qt Creator中的Qt GUI应用程序构建设置
- 找不到 Xcode 构建设置 - GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS
- 使用 VS2010 的 msbuild 构建时,我可以从命令行设置平台工具集吗?
- 使用XCODE 4.6.1的boost -什么是正确的构建设置
- cmake + xcode:错误"未定义PRODUCT_NAME构建设置"
- Eclipse CDT,构建设置- Hello World
- c++构建设置忽略注释中的更改
- 如何在Qt Creator中为不同的构建设置定义常量