Results 1 to 8 of 8

Thread: Reading a unicode names from a file???

  1. #1
    Join Date
    Mar 2006
    Posts
    47
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Reading a unicode names from a file???

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Reading a unicode names from a file???

    Show us a piece of actual code
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Mar 2006
    Posts
    47
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Reading a unicode names from a file???

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Reading a unicode names from a file???

    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
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Mar 2006
    Posts
    47
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Reading a unicode names from a file???

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading a unicode names from a file???

    If you were using Qt classes, you wouldn't have this problem.

    Qt Code:
    1. QChar SoftwareName[260*2];
    2. memset(SoftwareName,0x00,260*2);
    3. memcpy((void*)SoftwareName,(const void*)&Header.bSoftwareName,(260*2));
    To copy to clipboard, switch view to plain text mode 
    QChar is a class --- it isn't safe to initialize it using memcpy. Not mentioning that &Header.bSoftwareName is char **.

    This might work:
    Qt Code:
    1. QTextCodec *codec = QTextCodec::codecForName( "UTF-16" );
    2. QString name;
    3. if( codec != 0 ) {
    4. name = codec->toUnicode( Header.bSoftwareName, 2*260 );
    5. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Mar 2006
    Posts
    47
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Reading a unicode names from a file???

    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

  8. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading a unicode names from a file???

    Quote Originally Posted by darpan
    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.
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55
  2. QTextStream loses position while reading file
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2008, 15:47
  3. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. moc with same file names?
    By cjhuitt in forum Qt Programming
    Replies: 9
    Last Post: 27th April 2007, 20:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.