0

I m trying to convert QString with special character to const char but I did not succeed. my function is:

void class::func(const QString& fileName) // fileName = "â.tmp" 
{ 
  qDebug()<< fileName; // display "â.tmp"
  const char* cfileName = fileName.toAscii().data();
  qDebug() << cfileName;  // display "a?.tmp" 
}

qDebug()<< fileName display the true value that is "â.tmp" but after converting it to const a char*, I do not succeed to have the right value.

In the second time I try to use

const char* cfileName = QString::fromUtf8(fileName.toAscii().data());

but I did not still have the right value, it display the same thing: a?.tmp.

How can I fix this?

fancyPants
  • 50,732
  • 33
  • 89
  • 96
fa all
  • 11
  • 2

1 Answers1

0

ASCII character set does not have the character â, so what you are trying to do is impossible.

You could try this:

const char* cfileName = = fileName.toUtf8().data();
Esailija
  • 138,174
  • 23
  • 272
  • 326