[SOLVED] Strange QString issue: seems not to be closed ...



  • Dear all

    I encountered a strange issue when using QTextStream in combination with QString. It seems like the QString is not properly closed ...

    This is the code:
    @file.setFileName(fileNameCarePathwayData);
    if(file.open(QFile::ReadOnly | QFile::Text))
    {
    stream.setDevice(&file);

    while(!stream.atEnd())
    {
    line=stream.readLine();
    }

    }
    @

    When using this code the majority of lines seem O.K. (an example is the following line):
    "1234567 2222 VR 220110 1708 0083 Z32T A0410503UITSCHEIDING: R 123456 PAN MA KOFFI ******** 3K2104T "

    However some lines seem like not properly formed QStrings (an example is the following line, you can see that there was no closing quotes printed by the qDebug()):
    "1234567 0000 VR 220110 1708 0137 Z32 A5601693GEWICHT/LENGTE 123456

    When I tried to do operations on these not properly formed QStrings like extracting parts of it or appending to other QStrings, the behavior was unpredictable ...

    Could anybody give a suggestion to solve this problem?


  • Lifetime Qt Champion

    Hi,

    Are you sure that your file contains only printable characters ?



  • Dear Sir

    When I open the file with NotePad all symbols are displayed properly. The txt file which I try to read was output of a database extraction. Which type of (hidden) characters can cause this problem?
    The problem only appears in certain places of the file, however in these places I see nothing special in NotePad. How can I find out if there are non-printable characters here and which characters these are?

    Thanks in advance
    Hatchi


  • Lifetime Qt Champion

    You can analyze the content of the file with an hex editor for example



  • Dear Sir

    I used the free hex editor neo and I analyzed the lines which caused problems. They contained the hex code 00 multiple times. In the hex editor this character was displayed as a dot. For the rest I see nothing abnormal. Could it be that Qt has problems with this hex code 00?

    Is there some way to solve this problem programatically or should I replace this hex code in all data file by 20?

    Thanks
    Hatchi


  • Lifetime Qt Champion

    It's not a problem of Qt, 0x0 is a string termination char. Depending on what you want to do with the data, you'd rather use a QByteArray



  • I solved the problem by opening the files with notepad and saving them again. Notepad replaces automatically all 00 by 20.

    Thanks once more :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.