Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Strange QString issue: seems not to be closed ...
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hatchi
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you sure that your file contains only printable characters ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hatchi
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hatchi
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hatchi
                wrote on last edited by
                #7

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

                Thanks once more :)

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved