-1

I am trying to convert the c++ project from boost to pybind11

QString r = QString(PyString_AsString(result));"

QString r = QString(py::str(result));
gino247
  • 1
  • 2

2 Answers2

1

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.

DavidW
  • 29,336
  • 6
  • 55
  • 86
0

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));
HarryP2023
  • 298
  • 1
  • 13