From 7918fa30cfa1ad3c3bd91700dc9ef982aee16912 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 9 Apr 2012 15:09:48 +0200 Subject: [PATCH] Convenience functions --- src/common/qt.h | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/common/qt.h b/src/common/qt.h index f9c4f7364..44883c995 100644 --- a/src/common/qt.h +++ b/src/common/qt.h @@ -11,9 +11,30 @@ Written by Moritz Bunkus . */ -#ifndef __MTX_COMMON_QTCOMMON_H -#define __MTX_COMMON_QTCOMMON_H +#ifndef MTX_COMMON_QT_H +#define MTX_COMMON_QT_H -#define Q(s) QString::fromUtf8(s) +#define Q(s) to_qs(s) +#define QY(s) to_qs(Y(s)) -#endif // __MTX_COMMON_QTCOMMON_H +inline QString +to_qs(std::string const &source) { + return QString::fromUtf8(source.c_str()); +} + +inline QString +to_qs(std::wstring const &source) { + return QString::fromStdWString(source); +} + +inline std::string +to_utf8(QString const &source) { + return std::string{ source.toUtf8() }; +} + +inline std::wstring +to_wide(QString const &source) { + return source.toStdWString(); +} + +#endif // MTX_COMMON_QT_H