Qt: Add QtUtils::StringViewToQString()

This commit is contained in:
Connor McLaughlin 2022-01-31 15:24:19 +10:00 committed by refractionpcsx2
parent 280f5adb22
commit 8b9eee4961
2 changed files with 9 additions and 0 deletions

View File

@ -690,6 +690,11 @@ namespace QtUtils
return OpenURL(parent, QUrl(url));
}
QString StringViewToQString(const std::string_view& str)
{
return str.empty() ? QString() : QString::fromUtf8(str.data(), str.size());
}
wxString QStringToWxString(const QString& str)
{
return wxString(str.toStdWString());

View File

@ -19,6 +19,7 @@
#include <QtCore/QString>
#include <functional>
#include <initializer_list>
#include <string_view>
#include <optional>
Q_DECLARE_METATYPE(std::optional<bool>);
@ -79,6 +80,9 @@ namespace QtUtils
/// Opens a URL string with the default handler.
void OpenURL(QWidget* parent, const QString& url);
/// Converts a std::string_view to a QString safely.
QString StringViewToQString(const std::string_view& str);
// TODO: Get rid of wx interoperability later on.
wxString QStringToWxString(const QString& str);
QString WxStringToQString(const wxString& str);