Details
-
Suggestion
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
6.4.2
-
None
-
Like QString::fromCFString for Apple platforms (CoreFoundation).
But I haave zero experience with that winrt API, so I wouldn't know how to start. This task is likely to remain undone forever, because I will not implement it.
-
-
a81ea3d11 (dev), c79d9866f (6.5)
Description
Given that winrt is the modern API for windows OS and strings are often used while interacting with winrt APIs. There is a need for efficient string conversation between winrt::hstring and QString.
Currently, even in Qt code, following approach is used, which is hard to read and creates an unnecessary copy of string.
winrt::hstring text = L"Hello World"; //Current hstring to QString converstion auto text2 = QString::fromStdString(winrt::to_string(text);
Here's the suggested method that needs to be added
QString QString::fromHString(const winrt::hstring& string) { //Note that c_str() returns the underlying string without making any copy //https://learn.microsoft.com/en-us/uwp/cpp-ref-for-winrt/hstring#hstringc_str-function return QString::fromWCharArray(string.c_str()); }
Usage is much more simplified now
winrt::hstring text = L"Hello World"; //Current hstring to QString converstion auto text2 = QString::fromHString(text);
Note that QString to winrt::hstring is quite simple since winrt::hstring can be initialized using std::wstring. However, a QString::toHString() method would be nice to have as well.
QString text = "Hello World";
winrt::hstring text2(text.toStdWString());
Relevant Documentation:
https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/strings
https://learn.microsoft.com/en-us/uwp/cpp-ref-for-winrt/hstring