逃避空间QT [英] Escape Spaces in QT
问题描述
我想使用QString.split('')方法将输入命令拆分为命令
QStringList commandList = command.split('');
但是命令在其末尾有一个UNIX路径。即它看起来像
QString command = new QString(caommand -a -b / path / to\ specific / file );
路径命令由用户在运行时指定(用户转义路径中的任何空格)。由于某种原因command.split('');不会逃避空格。
我是QT的新手,它如何逃避空间?
感谢任何帮助
您可以使用 QDir :: toNativeSeparators()
将其转换为unix样式。并且分割接收结果的空格,虽然你必须弄清楚命令之间的空格在哪里和文件名中可能的空格在哪里
例如:
QString myUnixPath = QDir :: toNativeSeparators(/ home / path with spaces /);
将返回unix样式路径,而
QString qtPath = QDir :: fromNativeSeparators(/ path / with\ spaces /);
将返回/路径与空格/
I want to use the QString.split(' ') method to split a input command into the command
QStringList commandList = command.split(' ');
however command has a UNIX path at the end of it. i.e. it looks something like
QString command = new QString("caommand -a -b /path/to\ specific/file");
the path command is specified by the user at runtime(the user escapes any spaces in the path). For some reason command.split(' '); does not escape the spaces.
I am new to QT, how does it escape spaces?
Thanks for any help
You can use QDir::toNativeSeparators()
to convert it to unix style. And split received result by spaces, though you have got to figure out where are the spaces between commands and where are the possible spaces in filename
For example:
QString myUnixPath = QDir::toNativeSeparators("/home/path with spaces/");
will return unix style path, while
QString qtPath = QDir::fromNativeSeparators("/path/with\ spaces/");
will return /path with spaces/
这篇关于逃避空间QT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!