Qt Utilities: misc/conversion.h Source File

Qt Utilities 6.20.0 Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models

Loading...
Searching...
No Matches
conversion.h
Go to the documentation of this file.
1#ifndef QT_UTILITIES_CONVERSION_H
2#define QT_UTILITIES_CONVERSION_H
3
4#include "../global.h"
5
6#include <QString>
7
8#include <string>
9#include <string_view>
10
11namespace QtUtilities {
12
13 inline QByteArray toNativeFileName(const QString &fileName)
14{
15#if !defined(PLATFORM_WINDOWS) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER)
16 return fileName.toLocal8Bit();
17#else
18 return fileName.toUtf8();
19#endif
20}
21
22 inline QString fromNativeFileName(const char *nativeFileName, int size = -1)
23{
24#if !defined(PLATFORM_WINDOWS) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER)
25 return QString::fromLocal8Bit(nativeFileName, size);
26#else
27 return QString::fromUtf8(nativeFileName, size);
28#endif
29}
30
31 inline QString fromNativeFileName(const std::string &nativeFileName)
32{
33#if !defined(PLATFORM_WINDOWS) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER)
34 return QString::fromLocal8Bit(nativeFileName.data(), static_cast<int>(nativeFileName.size()));
35#else
36 return QString::fromUtf8(nativeFileName.data(), static_cast<int>(nativeFileName.size()));
37#endif
38}
39
40 inline QString qstringFromStdStringView(std::string_view stringView)
41{
42 return QString::fromUtf8(stringView.data(), static_cast<QString::size_type>(stringView.size()));
43}
44
45} // namespace QtUtilities
46
47#endif // QT_UTILITIES_CONVERSION_H
global.h
QtUtilities
!
Definition trylocker.h:8
QtUtilities::qstringFromStdStringView
QString qstringFromStdStringView(std::string_view stringView)
Definition conversion.h:40
QtUtilities::fromNativeFileName
QString fromNativeFileName(const char *nativeFileName, int size=-1)
Definition conversion.h:22
QtUtilities::toNativeFileName
QByteArray toNativeFileName(const QString &fileName)
Definition conversion.h:13