Retain latin accent characters C++ ISO-8859-1 - c++

A C++ program sends the following as an email subject with the following text:
Adjuntamos información existente en nuestra base de datos.
Si el informe llegase en blanco, quiere decir que no ha tenido ninguna incidencia en el periodo indicado o no figura información. Si desea responder a este correo, por favor, hágalo a
The encoding is set to ISO-8859-1. The text is getting sent to the email recipient as:
Adjuntamos información existente en nuestra base de datos.
Si el informe llegase en blanco, quiere decir que no ha tenido ninguna incidencia en el periodo indicado o no figura información. Si desea responder a este correo, por favor, hágalo a
What do I need set my encoding to have the accent characters remain as inputed?

CPJNSMTPBodyPart::CPJNSMTPBodyPart() : m_sCharset(_T("UTF-8")),
m_sContentType(_T("text/plain")),
m_pParentBodyPart(NULL),
m_bAttachment(FALSE),
m_pszRawBody(NULL),
m_ContentTransferEncoding(NO_ENCODING)
{
//Automatically generate a unique boundary separator for this body part by creating a guid
m_sBoundary = CreateGUID();
}

Related

How to capture the event whenever the items inside a listview are checked

I'm developing a plugin in QGIS 2.8.2 using Pyqt 4.
Well the idea is using the processing 'qgis:extractbylocation' from the QGIS algorithm provider to capture the studied area .
# Récupérer tous les iris qui s'intersectent avec la zone d'étude
res = processing.runalg('qgis:extractbylocation', irisLayer, layerZone, u'intersects', 0, None)
# Créer une couche vector issue de l'extraction des IRIS dans la zone
ObjectifVilleExtract.irisLayer = QgsVectorLayer(res['OUTPUT'], "IRIS dans la zone d'etude", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(ObjectifVilleExtract.irisLayer)
# Définir un ecodage Windows compatible avec le français
ObjectifVilleExtract.irisLayer.setProviderEncoding(u'iso-8859-1')
# Modifier l'encoage
ObjectifVilleExtract.irisLayer.dataProvider().setEncoding(u'iso-8859-1')
# Vérifier que le couche est valide sinon afficher que la couche est erronée
if not ObjectifVilleExtract.irisLayer.isValid():
print "Layer failed to load!"
Then showing the results on a listview:
ObjectifVilleExtract.features = ObjectifVilleExtract.irisLayer.getFeatures()
ObjectifVilleExtract.model = QStandardItemModel(ObjectifVilleExtract.features)
for feature in ObjectifVilleExtract.features:
item = QStandardItem(feature['nom_iris'])
item.setCheckable(True)
ObjectifVilleExtract.model.appendRow(item)
self.dlg.listView_3.setModel(ObjectifVilleExtract.model)
self.dlg.listView_3.show()
Now I want to capture checked item on the listview, to apply on its the following processes :
iter = ObjectifVilleExtract.features.getFeatures()
for feature in iter :
q1 = "SELECT nom_com FROM france_full_data.contours_iris WHERE code_iris='" + feature['code_iris'] + "' "
I tried to use the following code :
for feature in ObjectifVilleExtract.features:
while ObjectifVilleExtract.model.item(feature['nom_iris']) :
if ObjectifVilleExtract.model.item(feature['nom_iris']).ischecked():
ObjectifVilleExtract.iter = ObjectifVilleExtract.irisLayer.getFeatures()
irisTab=[]
for feature in ObjectifVilleExtract.iter :
q1 = "SELECT nom_com FROM france_full_data.contours_iris WHERE code_iris='" + feature['code_iris'] + "' "
the result is empty !

Reading and saving data from a Json

I have a .json document with data from my program that I want to reload in it. It looks like this:
{
"0 - Demanda": 100,
"0.1 - Ref. Temporal Demanda": "Mensual",
"1 - Tiempo de Suministro": 2,
"1.1 - Ref. Temporal Ts": "Diario",
"2 - Coste de Posesion": 20,
"2.1 - Ref. Temporal Cp": "Semanal",
"2.2 - Tipo de Coste de Posesion": "Dependiente",
"3 - Coste Unitario de Emision": 20,
"4 - Precio Unitario de compra": 30
}
To obtain this data I have filled each respective QLineEdit, QComboBox and QCheckBox, now I want to read the file I generated using this code:
void WResultados_Basico::on_pushButtonGuardar_clicked()
{
QJsonObject recordObject;
recordObject.insert("0 - Demanda", QJsonValue::fromVariant(d.demanda_original)); //d.anything is class with data
recordObject.insert("0.1 - Ref. Temporal Demanda", QJsonValue::fromVariant(d.ref_demanda));
recordObject.insert("1 - Tiempo de Suministro", QJsonValue::fromVariant(d.Ts_original));
recordObject.insert("1.1 - Ref. Temporal Ts", QJsonValue::fromVariant(d.ref_Ts));
recordObject.insert("2 - Coste de Posesion", QJsonValue::fromVariant(d.Cp_original));
recordObject.insert("2.1 - Ref. Temporal Cp", QJsonValue::fromVariant(d.ref_Cp));
recordObject.insert("2.2 - Tipo de Coste de Posesion", QJsonValue::fromVariant(d.Tipo_Cp));
recordObject.insert("3 - Coste Unitario de Emision", QJsonValue::fromVariant(d.Ce));
recordObject.insert("4 - Precio Unitario de compra", QJsonValue::fromVariant(d.PrecioUCompra));
QJsonDocument doc(recordObject);
qDebug() << doc.toJson();
QByteArray ba=doc.toJson();
QFile fid;
fid.setFileName("DatosBasico.json");
if (fid.open(QIODevice::WriteOnly))
{
fid.write(ba);
fid.close();
}
}
So, my goal is to refill the respective ComboBox, etc with the data I read. Maybe something like this could work but I don´t know how to assign a variable to each individual value:
{
QFile fid;
QByteArray ba;
fid.open("DatosBasico.json"::ReadOnly);
ba=fid.readAll();
doc.fromByteArray(ba);
fid.close();
}
Thank you for the help and patience
I ended up doing this, it works, looks horrible and it probably is super ineficient, but... it works :)
void Basico::on_pushButtonCargar_clicked()
{
QFile file("DatosBasico.json");
//Leer el archivoo que tiene el Json
if(!file.open(QFile::ReadOnly)){
qDebug()<< "Error, No se puede abrir el fichero.";
return;
}
QJsonDocument jsonDoc = QJsonDocument::fromJson(file.readAll());
d.demanda = jsonDoc.object().value("0 - Demanda").toDouble();
d.ref_demanda = jsonDoc.object().value("0.1 - Ref. Temporal Demanda").toString();
d.Ts = jsonDoc.object().value("1 - Tiempo de Suministro").toDouble();
d.ref_Ts = jsonDoc.object().value("1.1 - Ref. Temporal Ts").toString();
d.Cp = jsonDoc.object().value("2 - Coste de Posesion").toDouble();
d.ref_Cp = jsonDoc.object().value("2.1 - Ref. Temporal Cp").toString();
d.Tipo_Cp = jsonDoc.object().value("2.2 - Tipo de Coste de Posesion").toString();
d.Ce = jsonDoc.object().value("3 - Coste Unitario de Emision").toDouble();
d.PrecioUCompra = jsonDoc.object().value("4 - Precio Unitario de compra").toDouble();
file.close();
QString demanda_cargada=QString::number(d.demanda);
ui->lineEditDemanda->setText(demanda_cargada);
ui->comboBoxDemanda->setCurrentText(d.ref_demanda);
QString Ts_cargado=QString::number(d.Ts);
ui->lineEditTS->setText(Ts_cargado);
ui->comboBoxTS->setCurrentText(d.ref_Ts);
QString Cp_cargado=QString::number(d.Cp);
ui->lineEditCP->setText(Cp_cargado);
ui->comboBoxCP->setCurrentText(d.ref_Cp);
if (d.Tipo_Cp == "Dependiente")
{
ui->checkBoxDependiente->click();
}
if (d.Tipo_Cp == "Independiente")
{
ui->checkBoxIndependiente->click();
}
QString CE_cargado=QString::number(d.Ce);
ui->lineEditCe->setText(CE_cargado);
QString PUC_cargado=QString::number(d.PrecioUCompra);
ui->lineEditPrecioUCompra->setText(PUC_cargado);
}

flask_restplus' marshal_with returns response with null values

I am using flask_restplus to create a documented API. The marshal decorator controls what data actually gets rendered in your response, but I am having trouble rendering the data. I have the following code:
kpis_model = api.model('kpis', {
'cpl_actual': fields.Integer(description='costo por lead total del mes actual'),
'cpl_anterior': fields.Integer(description='costo por lead total del mes anterior'),
'cpl_diferencia': fields.Integer(description='diferencia de cpl_actual y cpl_anterior')
})
#data.route('/kpis/<cliente>/<mes>/<ano>')
#data.doc(params={'cliente': 'id de Facebook del cliente','mes':'el mes que se desea usar (dos digitos)','ano':'el ano que se desea usar (cuatro digitos)'})
class Kpis(Resource):
#data.marshal_with(kpis_model)
def get(self,cliente,mes,ano):
'''sacar KPIs principales'''
data = {}
data['cpl_actual'] = 300
data['cpl_anterior'] = 100
data['cpl_diferencia'] = data['cpl_actual'] - data['cpl_anterior']
return jsonify(data)
And then when I go to the route /kpis/cliente/mes/ano it returns this:
{
"cpl_diferencia": null,
"cpl_anterior": null,
"cpl_actual": null
}
Why are the values being returned as null ? can someone help me please!
You don't need to jsonify when using "marshal_with"
Just return "data"
return data
=)

Original route doesn't work

I have this code, but when i run the program the first cin doesn't work
I don't understand the reason
/*Metodo che calcola in byte la differenza tra il file non compresso e quello compresso aprendo
i due files, calcolando la lunghezza e facendo la differenza*/
void Huffman::rate_compression(){
cout<<"Inserisci il percorso del file originale:\t"<<endl;
string route;
cin>>route;
ifstream filenoncompresso;
filenoncompresso.open("route",ifstream::in);
filenoncompresso.seekg(0,filenoncompresso.end);
int lenght1=filenoncompresso.tellg();
filenoncompresso.seekg(0,filenoncompresso.beg);
filenoncompresso.close();
ifstream filecompresso;
string way;
route.erase(route.end()-4,route.end());
way=route+".aa";
filecompresso.open("way",ifstream::in);
filecompresso.seekg(0,filecompresso.end);
int lenght2=filecompresso.tellg();
lenght2-=1028;
filecompresso.seekg(0,filecompresso.beg);
cout<<"La differenza in byte tra il file non compresso e il file compresso e': "<<lenght1-lenght2<<endl;
}

getting <null> when trying to parse JSON response

i have problem with getting <null> when trying to display a string on a UILabel or either on the console, here is my code step by step :
NSArray *array=[[request responseString]JSONValue];
for (int i=0; i<[array count]; i++) {
NSDictionary *stationEnCours=[array objectAtIndex:i];
NSLog(#"%#",[stationEnCours objectForKey:#"ssiphone_adresse"]);
}
topStation.sstationAdress=[stationEnCours objectForKey:#"ssiphone_adresse"]; //global variable
adresseStation.text=[NSString stringWithFormat:#"%#",topStation.sstationAdress];//display on label
Now for both the console and the label i got <null> although i have check it in my data base it's not null. is that due to JSON parsing rules ? how can i fix it ? thx in advance for help :)
EDIT :
here is my response string :
2011-05-12 15:09:38.424 TopStation[1070:207] response string :[
{"ssiphone_idstation":"80","0":"80","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"Sans Plomb 95,SP95-E10,Gazole,GPLc,GNV,","4":"Sans Plomb 95,SP95-E10,Gazole,GPLc,GNV,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":"24h\/24","6":"24h\/24","ssiphone_telephone":"0400221997","7":"0400221997","ssiphone_sensdecirculation":"(Sens >> Aix-en-Prov.\/Marseille)","8":"(Sens >> Aix-en-Prov.\/Marseille)","ssiphone_adresse":"A 51 - Aire de la Champouse","9":"A 51 - Aire de la Champouse","ssiphone_ville":"BOUC-BEL-AIR","10":"BOUC-BEL-AIR","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.39532","12":"5.39532","ssiphone_latitude":"43.4416","13":"43.4416","ssiphone_nomstation":"RELAIS TOTAL DE LA CHAMPOUSE","14":"RELAIS TOTAL DE LA CHAMPOUSE","ssiphone_voie":"A 51","15":"A 51","ssiphone_enseigne":"TOTAL","16":"TOTAL","ssiphone_codepostal":"13320","17":"13320","ssiphone_referencegps":"TOTAL DE LA CHAMPOUSE A 51","18":"TOTAL DE LA CHAMPOUSE A 51","distance":17.3},
{"ssiphone_idstation":"86","0":"86","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"SP95-E10,Gazole,Super Gazole,GPLc,GNV,","4":"SP95-E10,Gazole,Super Gazole,GPLc,GNV,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":"24h\/24","6":"24h\/24","ssiphone_telephone":"0442591667","7":"0442591667","ssiphone_sensdecirculation":"","8":"","ssiphone_adresse":null,"9":null,"ssiphone_ville":"AIX-EN-PROVENCE","10":"AIX-EN-PROVENCE","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.43361","12":"5.43361","ssiphone_latitude":"43.5194","13":"43.5194","ssiphone_nomstation":"STATION BP","14":"STATION BP","ssiphone_voie":"","15":"","ssiphone_enseigne":"BP","16":"BP","ssiphone_codepostal":"13100","17":"13100","ssiphone_referencegps":"BP AIX EN PROVENCE","18":"BP AIX EN PROVENCE","distance":25.3},{"ssiphone_idstation":"89","0":"89","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"SP95-E10,E85,Gazole,Super Gazole,GPLc,","4":"SP95-E10,E85,Gazole,Super Gazole,GPLc,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":null,"6":null,"ssiphone_telephone":"0442264052","7":"0442264052","ssiphone_sensdecirculation":"(Centre ville) (A8 sortie 31)","8":"(Centre ville) (A8 sortie 31)","ssiphone_adresse":"467 Avenue Henri Mauriat","9":"467 Avenue Henri Mauriat","ssiphone_ville":"AIX-EN-PROVENCE","10":"AIX-EN-PROVENCE","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.4661","12":"5.4661","ssiphone_latitude":"43.5157","13":"43.5157","ssiphone_nomstation":null,"14":null,"ssiphone_voie":"","15":"","ssiphone_enseigne":"TOTAL","16":"TOTAL","ssiphone_codepostal":"13090","17":"13090","ssiphone_referencegps":"TOTAL DE L'ARC","18":"TOTAL DE L'ARC","distance":24.9},{"ssiphone_idstation":"91","0":"91","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"Sans Plomb 95,Sans Plomb 98,Gazole,Super Gazole,GPLc,GNV,","4":"Sans Plomb 95,Sans Plomb 98,Gazole,Super Gazole,GPLc,GNV,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":"L-S: 7h30-20h","6":"L-S: 7h30-20h","ssiphone_telephone":"0442958459","7":"0442958459","ssiphone_sensdecirculation":"(Dir.>> Aix Ouest) ","8":"(Dir.>> Aix Ouest) ","ssiphone_adresse":"Route de Berre - Jas de Bouffan","9":"Route de Berre - Jas de Bouffan","ssiphone_ville":"AIX-EN-PROVENCE","10":"AIX-EN-PROVENCE","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.41778","12":"5.41778","ssiphone_latitude":"43.5342","13":"43.5342","ssiphone_nomstation":null,"14":null,"ssiphone_voie":"","15":"","ssiphone_enseigne":"CASINO","16":"CASINO","ssiphone_codepostal":"13090","17":"13090","ssiphone_referencegps":"CASINO AIX EN PROVENCE","18":"CASINO AIX EN PROVENCE","distance":27.1}]
EDIT:
the response is coded like this in the server side :
$stationsFinales=array();
$stationsFinales=$this->EpurationStations($stationsIdeales);
sendResponse(200,json_encode($stationsFinales));
return true;
I don't know JSON very well but when I used it in my application, I solved a problem like this by using valueForKey: instead of objectForKey: and try to use this code:
NSArray *array = [[request responseString] JSONValue];
for (int i = 0; i < [array count]; i++) {
NSDictionary *stationEnCours = [array objectAtIndex:i];
NSLog(#"%#", [stationEnCours valueForKey:#"ssiphone_adresse"]);
topStation.sstationAdress = [stationEnCours valueForKey:#"ssiphone_adresse"];
}
adresseStation.text = [NSString stringWithFormat:#"%#", topStation.sstationAdress];
Consider this answer only as a test because, as I've said before, I don't know JSON very well.
However, I hope this can help you like me!