如何设置目录分隔符以匹配操作系统? [英] How to set the directory separator character to match the operating system?

查看:148
本文介绍了如何设置目录分隔符以匹配操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个qt应用程序,目的是将其移植到3种主要操作系统上.

I am writing a qt application, with the goal of it being portable to the 3 major operating systems.

我正在使用QFileDialog选择一个文件夹,然后将其添加到QListWidget.但是,即使我在Windows上,文件夹名称也将作为E:/media返回.我希望它返回E:\ media

I am using QFileDialog to select a folder, and then adding it to a QListWidget. However the folder name is being returned as E:/media even though I am on Windows. I would want it to return E:\media

我可以使用一个简单的字符串替换,但是在Linux/Mac上,拥有\ home \ user \ Documents

I could use a simple string replace, but then on Linux/Mac it would look weird to have \home\user\Documents

我的代码(如果有帮助的话):

My code if it helps:

void LibrariesForm::on_addButton_clicked()
{
    QString dir = QFileDialog::getExistingDirectory(this, tr("Select Folder"), "/", QFileDialog::ShowDirsOnly);

    if (dir.isNull() == true)
    {
        return;
    }

    ui->librariesList->addItem(new QListWidgetItem(dir, ui->librariesList, 0));
}

推荐答案

我想您正在寻找 QDir :: toNativeSeparators().

这篇关于如何设置目录分隔符以匹配操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆