PDA

View Full Version : Reading a unicode names from a file???



darpan
26th April 2006, 14:45
I have a file containing unicode software Names and i have to get these names and display on QMessageBox and QListView.

I am getting the right software names when i displaying the name i am only getting the first character of that name.

How i can get the full software names on messagebox and listbox.

Best Regards

zlatko
26th April 2006, 15:00
Show us a piece of actual code

darpan
27th April 2006, 06:06
FILE *fp = NULL;
HEADER_FILE Header;
HEADER_FILE *SearchHeaderStart=NULL,*SearchHeader=NULL;
memset(&Header,0x00,sizeof(HEADER_FILE));
QString CurrentPath=QDir::currentDirPath ()+"/HeaderFile.cfg";


fp = fopen((const char *)CurrentPath,"rb");
if(fp!= NULL)
{
while(1)
{
if(feof(fp))
break;
if(!SearchHeader)
SearchHeaderStart=SearchHeader=(HEADER_FILE*)callo c(1,sizeof(HEADER_FILE));
else
{
SearchHeader->next=(HEADER_FILE*)calloc(1,sizeof(HEADER_FILE));
SearchHeader=SearchHeader->next;
}
fread(&Header,sizeof(HEADER_FILE),1,fp);
memset( SearchHeader,0x00,sizeof(HEADER_FILE));
QChar SoftwareName[260*2];
memset(SoftwareName,0x00,260*2);
memcpy((void*)SoftwareName,(const void*)&Header.bSoftwareName,(260*2));
QString Name(SoftwareName,260);
QMessageBox::information(0,"Software Name",Name);



Following is a Structure to read data from a file Header.cfg in which data is written According to following structure and we have to read this structures from this file and make a link list but when i am displaying the Header.bSoftwareName then get the first character of softwareName right but how can i get the whole name because the name is written in unicode in .cfg file.
typedef struct tagAppendHdrFile
{
tagAppendHdrFile *next;
char bSoftwareName[260*2];
char bFileExt[260*2];
}HEADER_FILE;


Best Regards

zlatko
27th April 2006, 07:50
First of all use CODE tags for showing your code..also why you dont use QString instead of char *, QFile istead of FILE, and something like QPtrList istead of using pointer on next item in your struct ;)

darpan
27th April 2006, 14:30
Hi
Because i am using same type of code on windows plateform. Please help me how i can show the unicode name.

Thanks and regards

jacek
27th April 2006, 17:09
If you were using Qt classes, you wouldn't have this problem.


QChar SoftwareName[260*2];
memset(SoftwareName,0x00,260*2);
memcpy((void*)SoftwareName,(const void*)&Header.bSoftwareName,(260*2));
QChar is a class --- it isn't safe to initialize it using memcpy. Not mentioning that &Header.bSoftwareName is char **.

This might work:
QTextCodec *codec = QTextCodec::codecForName( "UTF-16" );
QString name;
if( codec != 0 ) {
name = codec->toUnicode( Header.bSoftwareName, 2*260 );
}

darpan
3rd May 2006, 07:55
Hi all,

I want to read unicode names written in a file. Which QT classes i have to use for handling unicode string and i have to display this string on QMessageBox or QlistView. please help me by giving code snippet.

Best Regards

Chicken Blood Machine
3rd May 2006, 17:28
Hi all,

I want to read unicode names written in a file. Which QT classes i have to use for handling unicode string and i have to display this string on QMessageBox or QlistView. please help me by giving code snippet.

Best Regards

It really helps if you try to read the documentation before asking a question.

Look at QFile, QTextCodec and QTextStream.