linux c++、Qt中的system()参数
parameter of system() in linux C++,Qt
当我使用长字符串(其中包含一些中文字符)调用system()时,
system()似乎没有正确处理我的参数
。system()收到的和我发送的不一样
//it based on Qt
void work(QString order)
{
system((const char*)order.toLocal8Bit());
// in terminal, it shows a wrong command different with what it should be.
}
当我调用
work( "g++ "+nfile+name+".cpp -o "+nfile+name+" 2>"+nfile+"compiler.out" );
nfile表示带有一些中文字符
如果您正在使用Qt,那么最好使用QProcess
而不是system
,请参阅此处
将字符串转换为UTF-8并传递给system()
:
void work(const QString &order)
{
system(order.toUtf8().constData());
}
根据toLocal8Bit()的文档
返回的字节数组未定义如果字符串包含非支持本地8位编码
我假设你正在使用的中文字符是不支持的。您可以尝试使用toUtf8。
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 函数调用中参数的顺序重要吗
- 部分定义/别名模板模板参数
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 使用不带参数的函数访问结构元素
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 使用单独的参数调用"boost::process::system()"时,获取"execv
- 您如何使用System()调用带有引号的参数的批处理文件
- c++中通过system()传递参数
- 随机参数使用System()
- System::对C++char*参数的字符串引用
- 如何将连接的字符串参数传递给system()函数
- 将项目从Visual Studio 2005迁移到2012 - System.参数nullexception,多个错误
- linux c++、Qt中的system()参数