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

How to use make “using” keyword within a method to accept it as class level
std::array-like class copy constructor
Access violation when using delete
C++ SFML compile error + install
Resizing 2D vector C++, Setting to 0
Finding the shortest word ladder between two given words and a dictionary
Is this function doing something wrong with the sockets?
How to use the same multidimensional array in many functions?
C++ namespace: using without owning
How can I change the border style of a Tab Control?
gtest installed with conan: undefined reference to `testing::internal::GetBoolAssertionFailureMessage`
how much memory would it take to store a reference to an object in C++?
Per vertex weighted normal keeping in mind the crease angle in OpenGL C++
std::vector< T >::iterator with accessible constructor
Permanently storing an environment variable when using CMake install
Calling derived class methods using array of base class pointers which has pointers to derived class objects

Categories

HOME
excel
videochat
objective-c
datatables
loops
dll
selenium-webdriver
firebase-authentication
junit
scenekit
slack
animate.css
houndify
linuxmint
instagram-api
external
http-headers
apache-spark-2.0
rectangles
url-rewriting
spring-transactions
slim
android-toast
ascii
sql-azure
m3u8
unity3d-unet
sensenet
google-fusion-tables
border
hudson
cdb
apache-felix
xbuild
jsx
oracle-data-integrator
formsets
lwip
jquery-ui-autocomplete
drools-fusion
chmod
puma
maven-exec-plugin
street-address
google-optimize
dos
powerdesigner
android-auto
ats
lift
sw-precache
background-position
cakephp-2.x
matlab-uitable
jedi-vim
topshelf
android-7.1-nougat
google-url-shortener
aide-ide
sharepoint-userprofile
owner
agile-project-management
page-load-time
grid-layout
kdiff3
tvml
frontpage
network-monitoring
ios9.3
dynamics-nav-2009
bitarray
xamarin-forms
protractor-net
aloha-editor
google-client
image-manipulation
gliffy
comfortable-mexican-sofa
unassigned-variable
swift-protocols
aglio
resharper-plugins
casbah
pixate
form-helpers
start-stop-daemon
chaplinjs
usermode
stubs
where-in
tiles2
apprequests
amber-smalltalk
sniffing
iunknown
jsonexception
operational-transform
nservicebus3
springmockito
actinic
expandoobject
log5j
google-instant-previews
tao
trx
cck
installshield-2008
moss2007enterprisesearch
table-driven
pdc2008
o3d

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