diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri
index 77788e3..e635fa4 100644
--- a/src/corelib/io/io.pri
+++ b/src/corelib/io/io.pri
@@ -32,6 +32,7 @@ HEADERS +=  \
         io/qresource_iterator_p.h \
         io/qsavefile.h \
         io/qstandardpaths.h \
+        io/qstandardpaths_p.h \
         io/qstorageinfo.h \
         io/qstorageinfo_p.h \
         io/qurl.h \
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp
index b41aee5..702f9c6 100644
--- a/src/corelib/io/qstandardpaths.cpp
+++ b/src/corelib/io/qstandardpaths.cpp
@@ -366,6 +366,30 @@ static bool existsAsSpecified(const QString &path, QStandardPaths::LocateOptions
 }
 
 /*!
+    This function enables or disables XDG locations on platforms where Qt can be configured
+    to use this kind of locations instead of locations following OS guidelines. This is a
+    feature that shouldn't be changed back and forth, so setXDGLocationsEnabled() has effect
+    only the first time it is called.
+    Currently this concerns only Mac OS X //and Cygwin?//
+ */
+void QStandardPaths::setXDGLocationsEnabled(bool xdgMode)
+{
+    static bool xdgSet = false;
+    if (!xdgSet) {
+        usingXDGLocations = xdgMode;
+        xdgSet = true;
+    }
+}
+
+/*!
+    This function returns true when XDG locations are used.
+ */
+bool QStandardPaths::isXDGLocationsEnabled()
+{
+    return usingXDGLocations;
+}
+
+/*!
    Tries to find a file or directory called \a fileName in the standard locations
    for \a type.
 
diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h
index e305450..96958a1 100644
--- a/src/corelib/io/qstandardpaths.h
+++ b/src/corelib/io/qstandardpaths.h
@@ -41,6 +41,8 @@ QT_BEGIN_NAMESPACE
 
 #ifndef QT_NO_STANDARDPATHS
 
+class Q_CORE_EXPORT QStandardPathsConfiguration;
+
 class Q_CORE_EXPORT QStandardPaths
 {
 public:
@@ -67,6 +69,8 @@ public:
         AppLocalDataLocation = DataLocation
     };
 
+    static bool isXDGLocationsEnabled();
+
     static QString writableLocation(StandardLocation type);
     static QStringList standardLocations(StandardLocation type);
 
@@ -90,10 +94,16 @@ public:
     static void setTestModeEnabled(bool testMode);
     static bool isTestModeEnabled();
 
+protected:
+    static void setXDGLocationsEnabled(bool xdgMode);
+
 private:
     // prevent construction
     QStandardPaths();
     ~QStandardPaths();
+    static bool usingXDGLocations;
+
+    friend class QStandardPathsConfiguration;
 };
 
 #endif // QT_NO_STANDARDPATHS
diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp
index 958b4ea..fdc2634 100644
--- a/src/corelib/io/qstandardpaths_android.cpp
+++ b/src/corelib/io/qstandardpaths_android.cpp
@@ -215,6 +215,8 @@ static QString getFilesDir()
     return (path  = QDir::homePath());
 }
 
+bool QStandardPaths::usingXDGLocations = false;
+
 QString QStandardPaths::writableLocation(StandardLocation type)
 {
     switch (type) {
diff --git a/src/corelib/io/qstandardpaths_blackberry.cpp b/src/corelib/io/qstandardpaths_blackberry.cpp
index 02d7c11..d28b320 100644
--- a/src/corelib/io/qstandardpaths_blackberry.cpp
+++ b/src/corelib/io/qstandardpaths_blackberry.cpp
@@ -47,6 +47,8 @@ static QString testModeInsert() {
         return QStringLiteral("");
 }
 
+bool QStandardPaths::usingXDGLocations = false;
+
 QString QStandardPaths::writableLocation(StandardLocation type)
 {
     QDir sharedDir = QDir::home();
diff --git a/src/corelib/io/qstandardpaths_ios.mm b/src/corelib/io/qstandardpaths_ios.mm
index 9b500f4..90a988b 100644
--- a/src/corelib/io/qstandardpaths_ios.mm
+++ b/src/corelib/io/qstandardpaths_ios.mm
@@ -58,6 +58,8 @@ static QString bundlePath()
     return QString::fromNSString([[NSBundle mainBundle] bundlePath]);
 }
 
+bool QStandardPaths::usingXDGLocations = false;
+
 QString QStandardPaths::writableLocation(StandardLocation type)
 {
     QString location;
diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm
index 13b8646..e3dc681 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>
@@ -134,8 +135,107 @@ static QString macLocation(QStandardPaths::StandardLocation type, short domain)
     return path;
 }
 
+bool QStandardPaths::usingXDGLocations = false;
+
+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 xdgCacheDirs()
+{
+    QStringList dirs;
+    // http://standards.freedesktop.org/basedir-spec/latest/
+    QString xdgConfigDirsEnv = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
+    if (xdgConfigDirsEnv.isEmpty()) {
+#ifndef QT_BOOTSTRAPPED
+        dirs.append(QDir::homePath() + QString::fromLatin1("/.cache"));
+#endif
+    } else {
+        dirs = xdgConfigDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
+
+        normaliseDirs(dirs);
+    }
+    return dirs;
+}
+
+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("/etc/xdg"));
+#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;
+}
+
 QString QStandardPaths::writableLocation(StandardLocation type)
 {
+    if (usingXDGLocations) {
+        const QString prefix = (isTestModeEnabled())? QDir::homePath() + QLatin1String("/.qttest") : QDir::homePath();
+        QString path;
+        switch (type) {
+        case GenericDataLocation:
+        case AppDataLocation:
+        case AppLocalDataLocation:
+            path = prefix + QLatin1String("/.local/share");
+            if (type != GenericDataLocation)
+                appendOrganizationAndApp(path);
+            return path;
+        case GenericCacheLocation:
+        case CacheLocation:
+            path = prefix + QLatin1String("/.cache");
+            if (type == CacheLocation)
+                appendOrganizationAndApp(path);
+            return path;
+        case GenericConfigLocation:
+        case ConfigLocation:
+            return prefix + QLatin1String("/.config");
+        default:
+            break;
+        }
+    }
+
     if (isTestModeEnabled()) {
         const QString qttestDir = QDir::homePath() + QLatin1String("/.qttest");
         QString path;
@@ -182,6 +282,22 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
 {
     QStringList dirs;
 
+    if (usingXDGLocations ) {
+        switch (type) {
+        case GenericDataLocation:
+            dirs.append(xdgDataDirs());
+            break;
+        case GenericConfigLocation:
+        case ConfigLocation:
+            dirs.append(xdgConfigDirs());
+            break;
+        case GenericCacheLocation:
+        case CacheLocation:
+            dirs.append(xdgCacheDirs());
+            break;
+        }
+    }
+
     if (type == GenericDataLocation || type == AppDataLocation || type == AppLocalDataLocation || type == GenericCacheLocation || type == CacheLocation) {
         const QString path = macLocation(type, kOnAppropriateDisk);
         if (!path.isEmpty())
@@ -189,6 +305,14 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
     }
 
     if (type == AppDataLocation || type == AppLocalDataLocation) {
+        if (usingXDGLocations) {
+            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);
diff --git a/src/corelib/io/qstandardpaths_p.h b/src/corelib/io/qstandardpaths_p.h
new file mode 100644
index 0000000..d1d7789
--- /dev/null
+++ b/src/corelib/io/qstandardpaths_p.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSTANDARDPATHS_P_H
+#define QSTANDARDPATHS_P_H
+
+#include <QtCore/qstandardpaths.h>
+
+QT_BEGIN_NAMESPACE
+
+
+#ifndef QT_NO_STANDARDPATHS
+
+struct Q_CORE_EXPORT QStandardPathsConfiguration
+{
+    QStandardPathsConfiguration(bool useXDGLocations)
+    {
+        QStandardPaths::setXDGLocationsEnabled(useXDGLocations);
+    }
+};
+
+#endif // QT_NO_STANDARDPATHS
+
+QT_END_NAMESPACE
+
+#endif // QSTANDARDPATHS_P_H
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 2ad6dfa..8d25055 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -62,6 +62,8 @@ static void appendOrganizationAndApp(QString &path)
 #endif
 }
 
+bool QStandardPaths::usingXDGLocations = true;
+
 QString QStandardPaths::writableLocation(StandardLocation type)
 {
     switch (type) {
diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp
index 5e56db3..d25c32b 100644
--- a/src/corelib/io/qstandardpaths_win.cpp
+++ b/src/corelib/io/qstandardpaths_win.cpp
@@ -85,6 +85,8 @@ static inline int clsidForAppDataLocation(QStandardPaths::StandardLocation type)
 #endif
 }
 
+bool QStandardPaths::usingXDGLocations = false;
+
 QString QStandardPaths::writableLocation(StandardLocation type)
 {
     QString result;
diff --git a/src/corelib/io/qstandardpaths_winrt.cpp b/src/corelib/io/qstandardpaths_winrt.cpp
index 5c09b48..73b516f 100644
--- a/src/corelib/io/qstandardpaths_winrt.cpp
+++ b/src/corelib/io/qstandardpaths_winrt.cpp
@@ -60,6 +60,8 @@ static QString convertCharArray(const wchar_t *path)
     return QDir::fromNativeSeparators(QString::fromWCharArray(path));
 }
 
+bool QStandardPaths::usingXDGLocations = false;
+
 QString QStandardPaths::writableLocation(StandardLocation type)
 {
     QString result;
