[英]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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.