I am trying to convert the c++ project from boost to pybind11
QString r = QString(PyString_AsString(result));"
QString r = QString(py::str(result));
In Pybind11 think you need to go through a std::string
QString r = QString(result.cast<std::string>().c_str());"
You could of course just use PyString_AsString
yourself:
QString r = QString(PyString_AsString(result.ptr());
PyString_AsString
is from a Python version that has been completely unsupported for >2 years. You should consider whether you should be using it at all.
To add to the above answer, avoid using PyString_AsString
, that is a raw C python api call.
Instead convert the python string to a std::string
std::string intermediateStdString = std::string(py::str(result));
Then you can convert that std::string
to a QString
QString finalQString = QString::fromStdString(intermediateStdString));