我是 C++ 新手,所以我想我掉进了 C++ 新手陷阱。
我尝试执行以下操作:
QString sdkInstallationDirectory=getenv("somEnv");
QString someSourceDir=sdkInstallationDirectory+"\\Data\\"+someReference+ "\\src";
我遇到了段错误。
我猜这是因为 const 字符的连接和分配给 someSourceDir
QString 的内存不足。
我的错误到底是什么?我怎样才能做这个连接?
最佳答案
char * getenv ( const char * name );
A null-terminated string with the value of the requested environment variable, or NULL if that environment variable does not exist.
为什么不检查结果?
编辑。
因此,不需要检查指针。
For historical reasons, QString distinguishes between a null string and an empty string. A null string is a string that is initialized using QString's default constructor or by passing (const char *)0 to the constructor.
关于c++ - Qt - C++ 字符串连接段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11611438/