-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUtilsQt.h
48 lines (35 loc) · 933 Bytes
/
UtilsQt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef UTILSQT_H
#define UTILSQT_H
#ifdef QT_VERSION
#include "UtilsMisc.h"
namespace Utils
{
#ifdef _WIN32
static inline std::string QStringToStdString(const QString &str, bool locale=true)
{
if (locale && !IsUtf8())
{
QByteArray array = str.toLocal8Bit();
return std::string(array.data());
}
return str.toStdString();
}
static inline QString StdStringToQString(const std::string &str, bool locale=true)
{
if (locale && !IsUtf8())
return QString::fromLocal8Bit(str.c_str());
return QString::fromStdString(str);
}
#else
static inline std::string QStringToStdString(const QString &str)
{
return str.toStdString();
}
static inline QString StdStringToQString(const std::string &str)
{
return QString::fromStdString(str));
}
#endif
}
#endif // QT_VERSION
#endif // UTILSQT_H