QT4> QT5 for QDesktopServices :: storageLocation

时间:2018-01-30 22:09:09

标签: qt

我正在尝试将以下代码转换为QT5版本:

QString getSaveFileName(QWidget *parent, const QString &caption,
                                 const QString &dir,
                                 const QString &filter,
                                 QString *selectedSuffixOut)
{
    QString selectedFilter;
    QString myDir;
    if(dir.isEmpty()) // Default to user documents location
    {
        myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
    }
    else

但遗憾的是我收到了以下错误:

error: no member named 'storageLocation' in 'QDesktopServices'
        myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
                ~~~~~~~~~~~~~~~~~~^

error: no member named 'DocumentsLocation' in 'QDesktopServices'
        myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
                                                  ~~~~~~~~~~~~~~~~~~^

1 个答案:

答案 0 :(得分:3)

从Qt 5开始,storageLocation()的{​​{1}}和displayName()方法被QDesktopServices类提供的功能所取代,因此您的QStandardPaths可以像这样:

myDir