tags:

views:

37

answers:

2

Hi ..

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

+3  A: 

QString::toWCharArray() does not zero-terminate the array. Without an explicit array length with QString::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 with QString::fromWCharArray().

As always, the documentation is your friend.

laalto
+1  A: 

This is just my guess.

According to the toWCharArray documentation: This function does not append a null character to the array. The returned string was not properly terminated with null. When you printed it, the part of memory after the memory allocated for the Drive array was also printed until a null byte is reached.

John