I have a string named aDrive = "H:/"
i want to convert this string into WCHAR so used like below
WCHAR Drive[4];
aDrive.toWCharArray ( Drive ) ;
when i printed it qDebug ()<<QString::fromWCharArray ( Drive );
it displays like "H:/???"
why i get the starnge charracters at the end..
Thank you for your time
QString::toWCharArray()does not zero-terminate the array. Without an explicit array length withQString::fromWCharArray(), it will read wchars until a zero wchar is read. In this case, you’ll have to add the zero wchar yourself at the end, or use explicit length parameter withQString::fromWCharArray().As always, the documentation is your friend.