Hi i am developping an open source sms application and i am using Qt. But now i have various problem with the encodings. I am using this library for various pdu encoding and decoding https://sourceforge.net/projects/pdulib/ In gsm there 3 main encodings Default 7bit alphabet, UCS2 and 8bit data. So when For 7bit encoding the library expect std::string argument so i am passing it like this
QString message = lineEdit->toPlainText();
std::string msg_to_pass = message.toStdString();
The sms is correctly sended but when there is accent characters the sms arrives with bad characters like 'C?' the sign of bad charset/encoding. Note that it is the phone that show it. So decoding error is very low.
But when i am using the UCS2 encoding
QString message = lineEdit->toPlainText();
std::wstring msg_to_pass = message.toStdWString();
because the library requires std::wstring for UCS2 the characters with accent got printed well. But the problem is when i am decoding a sms received. I have modified function of this library to suit my needs but again characters with accent have a problem. Here is the function
template<class MsgT>
void PrintUserData(const MsgT& msg, QString &message)
{
if (MsgT::DefaultAlphabet == msg.alphabet())
{
message = QString::fromStdString(msg.template userData<typename MsgT::DefaultUserData>().userData());
std::cout << "User Data: " << msg.template userData<typename MsgT::DefaultUserData>().userData() << std::endl;
}
else if(MsgT::UCS2Alphabet == msg.alphabet())
{
QTextStream ts(stdout);
message = QString::fromStdWString( msg.template userData<typename MsgT::UCS2UserData>().userData());
qInfo()<< message;
std::wcout << L"User Data: " << msg.template userData<typename MsgT::UCS2UserData>().userData() << std::endl;
}
else if(MsgT::EightBitDataAlphabet == msg.alphabet())
{
qInfo()<< "3";
const std::vector<unsigned char>& data = msg.template userData<typename MsgT::EightBitUserData>().userData();
std::cout << "User Data: ";
PrintBinary(data.begin(), data.end());
std::cout << std::endl;
}
}
I have tested various pdu lib for C++ and this seems to be the best for me. My think is that i am doing something bad with the std::string and std::wstring but i can't figure what. Also i know that UCS2 is UTF-16 but i have read that there is small differences. My locale is FR (French) I am using Qt 5.9 Sorry for my english.