Zna ktoś sposób jak wyiskać z QStringu jeden określony znak ?? W zwykłych stringach robi się to np.
string kotek;
litera = kotek[5];
A jak to zrobić w QStringach ?? Zna ktoś sposób ?? Zaznaczę że konwersja na tablice nie wchodzi w grę, chyba że zna ktoś sposób jak prze konwertować poprawnie polskie znaki.
A nie da się?
Google napisał(a)
QCharRef QString::operator[] ( int position )
Returns the character at the specified position in the string as a modifiable reference.
Example:
QString str;if (str[0] == QChar('?')) str[0] = QChar('_');
The return value is of type QCharRef, a helper class for QString. When you get an object of type QCharRef, you can use it as if it were a QChar &. If you assign to it, the assignment will apply to the character in the QString from which you got the reference.
See also at().
Dobra, przepraszam. Źle się wyraziłem, bo szukam tego już tyle że mam mętlik w głowie. To może napisze na spokojnie w czym problem. Mam Qstringa w którym są polskie znaki, prze konwertowałem go na char w taki sposób:
QByteArray imie_string = ui->imie->toPlainText().toAscii();
const char *text = imie_string.data();
I po takiej konwersji polskie znaki zamieniło mi na "?" pytajniki.... Więc moje pytanie jest takie, zna ktoś może inny sposób konwersji ?? Albo w jaki sposób przypisać jeden znak z QString na char ??
Próbowałem tak:
QString temp;
char a = temp[x];
ale otrzymałem błąd którego nie rozumiem (zaawansowany to ja nie jestem)
error: cannot convert 'QCharRef' to 'char' in assignment
QTextCodec ?
wywołujesz sobie:
QTextCodec::setCodecForCStrings( QTextCodec::codecForName( "cp1250" ) );
I masz polskie znaki.
Co do char:
QString str = "ąęśćźć";
char c = str.at( 2 ).toAscii();
QMessageBox::information( 0, 0, QChar( c ) );
albo jeszcze lepiej
QString str = "ąęśćźć";
QChar c = str.at( 2 );
QMessageBox::information( 0, 0, c );