c++


converting `\oct` to `char` in Qt


I have a string like
QString result ("very much text\\374more Text");
and the backslash-int-int-int represents a char writen in an octal number. In this case it is a ü. I want to have the char ü instead of the backslash representation.
That's what I tried:
while (result.contains('\\'))
if(result.length() > result.indexOf('\\') + 3)
{
bool success;
int i (result.mid(result.indexOf('\\') + 1, 3).toInt(&success, 8));
if (success)
{
//convert i to a string
QString myStringOfBits ("\\u" + QString::number(i, 16));
//QChar c = myStringOfBits.toUtf8();
//qDebug() << c;
}
}
I'm a noob, I know that
all code in qt should be utf8 by default, so you could just put the ü in the string.
Let's say we have a result string:
QString result ("Ordner mit \\246 und \\214"); //its: "Ordner mit ö and Ö"
there is a solution with:
result = QString::fromLatin1("Ordner mit \\246 und \\214");
but you can't put in a variable. If you want to put in a variable you might use (char) to the (decimal)octal to its char equivalent:
while (result.contains("\\ ")) //replace spaces
result = result.replace("\\ ", " ");
while (result.contains('\\')) //replace special characters
if(result.length() > result.indexOf('\\') + 3)
{
bool success;
int a (result.mid(result.indexOf('\\') + 1, 3).toInt(&success, 8)); //get the octal number as decimal
//qDebug() << a; //print octal number
//qDebug() << (char)a; //qDebug() will print "" because it can't handle special characters
if (success)
{
result = result.mid(0, result.indexOf('\\')) +
(char)a + //replace the special character with the char equivalent
result.mid(result.indexOf('\\') + 4);
}
}
qDebug() won't display special characters but GUI does:
so it works :) thanks to all of you

Related Links

C++ weak_ptr creation performance
bad memory allocation while doing opencv2 bruteforce matcher
Is it possible to obtain a QModelIndex from col and row [closed]
What actually happens in C++ when I call “delete?” [closed]
Making program to close automatically after clicking on NO on a MessageBox (C++)
opengl32.lib wont link to project
Condition checking: if(x==0) vs. if(!x)
How to show list of strings in QT at run time?
Passing struct to function in C++ [closed]
Why is this swap function call ambiguous? [duplicate]
C++ Storing rows as part of a 2D array and then printing a row [closed]
Segfault: Track down “invalid read” “free'd at”
Comparing 2 text files
Assigning a string to an element of an array?
Memory allocation and assignment in C++ with openMP
Change QComboBox item text in delegate

Categories

HOME
audio
centos
angular-material2
mongoose
mono
basecamp
wolfram-mathematica
userform
keyboard-shortcuts
memcached
google-vr
uinavigationcontroller
crystal-reports-xi
slim
apostrophe-cms
bpm
ascii
mit-scratch
corba
spring4d
twitter-typeahead
subplot
skybot
4d-database
divide-and-conquer
spring-statemachine
mitmproxy
file-permissions
django-channels
indexoutofrangeexception
apl
http-caching
android-adapter
get-eventlog
sharethis
spamassassin
bootstrapping
ngrx-effects
homescreen
xilinx-edk
oclazyload
instrumentation
ios6
grunt-string-replace
mosync
javac
sp-executesql
wamp-protocol
terminal-emulator
django-compressor
db-schema
webpack-style-loader
miva
android-gson
magicalrecord
powerview
greenlets
jquery-tags-input
gyp
windows-firewall-api
turtle-rdf
blackberry-simulator
mindbody
divider
velocity.js
jlist
offsetheight
beta-testing
xlet
unique-constraint
uiactivity
gamma-function
.a
agsxmpp
kismet-wireless
centura
sequel
sqloledb
fast-esp
resharper-plugins
runscope
openacs
telerik-test-studio
microsoft-commerce-server
usermode
tiles2
scite
node-http-proxy
delphiscript
system.speech.recognition
outlook-2003
server-side-scripting
backbone-forms
ipad-2
dotfuscator
trusted-timestamp
capability
mercurial-subrepos
nsinteger
struts-config
getprocaddress
nested-queries
rails-models
tibco-gi
progressive-enhancement

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App