QTextEdit bzw. QString in ASCII7

Alles rund um die Programmierung mit Qt
lefrosch
Beiträge: 15
Registriert: 9. Mai 2007 20:55

Beitrag von lefrosch »

const char QChar::toAscii () const
Returns the character value of the QChar obtained using the current codec used to read C strings, or 0 if the character is not representable using this codec. The default codec handles Latin-1 encoded text, but this can be changed to assist developers writing source code using other encodings.
The main purpose of this function is to preserve ASCII characters used in C strings. This is mainly useful for developers of non-internationalized software.
Bekomm ich dort nicht den ascii wert? wie bekomm ich dann den ascii-wert?
Burgpflanze
Beiträge: 89
Registriert: 24. Februar 2006 16:41
Wohnort: Dresden

Beitrag von Burgpflanze »

Du kannst es ja auch mit einer while-Schleife machen:

Code: Alles auswählen

QString text = ui.textEdit.toPlainText();
int counter = text.length() -1;

while( counter > -1 )
{
	if( text.at( counter ).toAscii() > 127 )
		text.remove( counter, 1 );
	else
		counter--;
}
Gruß, Peter
NoobSaibot
Beiträge: 99
Registriert: 27. Januar 2005 15:55

Beitrag von NoobSaibot »

toAscii() liefert ein QByteArray. ich glaube das kann man nicht direkt mit einem integer wert vergleichen. warum castest du den char nicht vorher?
lefrosch
Beiträge: 15
Registriert: 9. Mai 2007 20:55

Beitrag von lefrosch »

danke. ich habs jetzt hinbekommen.

Code: Alles auswählen

f( text.at(i).unicode()>127 ) { ...
Antworten