0

I am using a qstring and using the function toStdString(). When I do this I lose a minus sign:

'332-_09I_W'

this text becomes:

'332_09I_W'

What can I do to prevent this?

EDIT: Actually, the problem is not when i use toStdString(), it is when I set the text in my qTextEdit. The change occurs here:

myTextEdit->setHtml(myString);
user1216527
  • 145
  • 1
  • 1
  • 11
  • 1
    I write: `QString qs("332-_09I_W"); std::string ss = qs.toStdString(); cout << ss << endl;` and the output is OK. – asclepix Jul 03 '13 at 14:55
  • yes, sorry I found out that wasn't the problem I was having. Thanks for investigating this to double check me. – user1216527 Jul 03 '13 at 14:57
  • That's not really a HTML string, is it? – Stephen Chu Jul 03 '13 at 15:14
  • The problem doesn't just occur with the text edit. When i try and set the text of a line edit the soft hyphen disappears. I'm even having troubles pasting the soft hyphen into this edit box. – user1216527 Jul 03 '13 at 15:29

1 Answers1

0

I've tried:

QString qs("332-_091_W");
std::string st = qs.toStdString();
ui->textEdit->setHtml(st.c_str());

It gives no problem to me. Which version of Qt are you using?

However, from the documentation:

setHtml() changes the text of the text edit. Any previous text is removed and the undo/redo history is cleared. The input text is interpreted as rich text in html format. Note: It is the responsibility of the caller to make sure that the text is correctly decoded when a QString containing HTML is created and passed to setHtml().

The minus/hyphen symbol is ambiguous in HTML, try to change it in the QString (before passing it to setHtml()) with &minus;

asclepix
  • 7,971
  • 3
  • 31
  • 41
  • Hey thanks for the feedback! it's not a regular hyphen/minus that I'm having problems with. It's the soft hyphen (unicode U+00AD). If you type in the unicode into microsoft word, highlight it and press Alt+x you will see the character I am trying to display in any line edit in Qt 4.7.4. – user1216527 Jul 05 '13 at 14:36
  • this is the case for when I use setText and setHtml – user1216527 Jul 05 '13 at 14:39
  • '­' it seems a weird character... I can't see it in many apps. Change the symbol, if you can. – asclepix Jul 05 '13 at 21:28