Escape Spaces in QT

大城市里の小女人 提交于 2019-12-11 12:39:49

问题


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


回答1:


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/



来源:https://stackoverflow.com/questions/15512207/escape-spaces-in-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!