diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h
index e305450..98f2d94 100644
--- a/src/corelib/io/qstandardpaths.h
+++ b/src/corelib/io/qstandardpaths.h
@@ -68,7 +68,15 @@ public:
     };
 
     static QString writableLocation(StandardLocation type);
+#ifdef Q_OS_OSX
+#ifdef QT_UNIX_STANDARDPATHS
+    static QStringList standardLocations(StandardLocation type, bool useOSXStandardLocations=false);
+#else
+    static QStringList standardLocations(StandardLocation type, bool useOSXStandardLocations=true);
+#endif
+#else
     static QStringList standardLocations(StandardLocation type);
+#endif
 
     enum LocateOption {
         LocateFile = 0x0,
diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm
index 13b8646..f5993a1 100644
--- a/src/corelib/io/qstandardpaths_mac.mm
+++ b/src/corelib/io/qstandardpaths_mac.mm
@@ -38,6 +38,7 @@
 
 #ifndef QT_BOOTSTRAPPED
 #include <qcoreapplication.h>
+#include <qlibraryinfo.h>
 #endif
 
 #include <CoreFoundation/CoreFoundation.h>
@@ -178,9 +179,70 @@ QString QStandardPaths::writableLocation(StandardLocation type)
     }
 }
 
-QStringList QStandardPaths::standardLocations(StandardLocation type)
+static void normaliseDirs(QStringList &dirs)
+{
+    // Normalise paths, skip relative paths
+    QMutableListIterator<QString> it(dirs);
+    while (it.hasNext()) {
+        const QString dir = it.next();
+        if (!dir.startsWith(QLatin1Char('/')))
+            it.remove();
+        else
+            it.setValue(QDir::cleanPath(dir));
+    }
+
+    // Remove duplicates from the list, there's no use for duplicated
+    // paths in XDG_CONFIG_DIRS - if it's not found in the given
+    // directory the first time, it won't be there the second time.
+    // Plus duplicate paths causes problems for example for mimetypes,
+    // where duplicate paths here lead to duplicated mime types returned
+    // for a file, eg "text/plain,text/plain" instead of "text/plain"
+    dirs.removeDuplicates();
+}
+
+static QStringList xdgConfigDirs()
+{
+    QStringList dirs;
+    // http://standards.freedesktop.org/basedir-spec/latest/
+    QString xdgConfigDirsEnv = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
+    if (xdgConfigDirsEnv.isEmpty()) {
+#ifndef QT_BOOTSTRAPPED
+        dirs.append(QLibraryInfo::location(QLibraryInfo::PrefixPath) + QString::fromLatin1("/config"));
+#endif
+    } else {
+        dirs = xdgConfigDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
+
+        normaliseDirs(dirs);
+    }
+    return dirs;
+}
+
+static QStringList xdgDataDirs()
 {
     QStringList dirs;
+    // http://standards.freedesktop.org/basedir-spec/latest/
+    QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
+    if (xdgDataDirsEnv.isEmpty()) {
+#ifndef QT_BOOTSTRAPPED
+        dirs.append(QLibraryInfo::location(QLibraryInfo::PrefixPath) + QString::fromLatin1("/share"));
+#endif
+    } else {
+        dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
+
+        normaliseDirs(dirs);
+    }
+    return dirs;
+}
+
+QStringList QStandardPaths::standardLocations(StandardLocation type, bool useOSXStandardLocations)
+{
+    QStringList dirs;
+
+    if (!useOSXStandardLocations) {
+        if (type == GenericDataLocation) {
+            dirs.append(xdgDataDirs());
+        }
+    }
 
     if (type == GenericDataLocation || type == AppDataLocation || type == AppLocalDataLocation || type == GenericCacheLocation || type == CacheLocation) {
         const QString path = macLocation(type, kOnAppropriateDisk);
@@ -188,7 +250,21 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
             dirs.append(path);
     }
 
+    if (!useOSXStandardLocations) {
+        if (type == GenericConfigLocation || type == ConfigLocation) {
+            dirs.append(xdgConfigDirs());
+        }
+    }
+
     if (type == AppDataLocation || type == AppLocalDataLocation) {
+        if (!useOSXStandardLocations) {
+            QStringList xdgDirs = xdgDataDirs();
+            for (int i = 0; i < xdgDirs.count(); ++i) {
+                appendOrganizationAndApp(xdgDirs[i]);
+            }
+            dirs.append(xdgDirs);
+        }
+
         CFBundleRef mainBundle = CFBundleGetMainBundle();
         if (mainBundle) {
             CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle);
