Skip to content

Commit

Permalink
Fix string conversion issues with emoji characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Silarn committed Nov 29, 2023
1 parent 7a885ad commit f4ee4da
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pybind11-qt/pybind11_qt_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ namespace pybind11::detail {
PyObject* strPtr =
PyUnicode_Check(objPtr) ? PyUnicode_AsUTF8String(objPtr) : objPtr;

if (!strPtr) {
return false;
}

// Extract the character data from the python string
value = QString::fromUtf8(PyBytes_AsString(strPtr));

Expand All @@ -68,8 +72,7 @@ namespace pybind11::detail {
handle /* parent */)
{
static_assert(sizeof(QChar) == 2);
return PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, src.constData(),
src.length());
return PyUnicode_FromString(src.toStdString().c_str());
}

bool type_caster<QVariant>::load(handle src, bool)
Expand Down

0 comments on commit f4ee4da

Please sign in to comment.