In my Qt GUI app I use libwebrtc. From one on callbacks I want to emit signal with data, which is std::string. As core app logic use QString, I want convert std::string to Qstring. I try following:
QString::fromStdString(stdstr)
QString::fromLatin1(stdstr.data())
Both of this return broken text, something like this
Only working way for me was
QString qstr;
for(uint i =0; i< stdstr.length(); i++)
qstr.append(stdstr.at(i));
Here my thoughts about reason of problem:
- Encoding problems.
- Binary problems
About encoding, libwebrtc should return std::string in UTF-8 by default, same as QString.
About binary. As I understand Qt built with GCC and corresponding stdlib, but libwebrtc build with CLang and libc++. For building I also specify usinng QMAKE_CXXFLAGS += -stdlib=libc++
What is correct way to convert types here?
UPD
I compare length of converted string and source string, they are very different.
For std::string I get 64, and for converted QString I get 5.
UPD2
Here is full function and corresponding slot for SPDGen signal
void foo(const webrtc::IceCandidateInterface *candidate) override {
std::string str;
candidate->ToString(&str);
QString qstr = QString::fromStdString(str);
qDebug() << qstr;
Q_EMIT SPDGen(qstr);
}
connect(conductor, &Conductor::SPDGen, this, [=](QString value){
ui->textEdit->setText(value);
});