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. Parsing a text file written with qSetFieldWidth

Parsing a text file written with qSetFieldWidth

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 953 Views
  • 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
    heliosbird
    wrote on last edited by
    #1

    Hello, I wrote a text file using qSetFieldWidth to format the columns (different columns have different widths). The last column was reserved for special notes, which can contain spaces. Is there a way to parse the file using QTextStream and split each line based on the fieldWidth?

    For example:
    The text file could look like this:

    @ ID StartTime EndTime GoodExample Problem Complexity Priority Note
    1 17:27:46:778 08:34:11:815 no None NA NA S
    2 08:34:11:816 08:34:11:946 no None NA NA T
    3 08:34:17:437 08:34:17:570 no None NA NA G
    4 08:34:17:437 08:34:17:570 no None NA NA G
    5 08:34:23:425 08:34:23:557 no None NA NA G
    6 08:36:50:114 08:36:58:049 no None NA NA C, T, G @
    Note: start of each line is the ID (1, 2, 3, etc.), but I couldn't find a good way to format it here.

    I would like the string list of the sixth line that looks like this:

    • 6
    • 17:27:46:778
    • 08:34:11:815
    • no
    • None
    • NA
    • NA
    • C, T, G

    Is there a simple(ish) way to do this? Thanks.

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

      Hi,

      You could try with QString::split and a QRegularExpression like \s

      Hope it helps

      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
        heliosbird
        wrote on last edited by
        #3

        Thanks! That's basically what I ended up doing, I was just hoping there was something symmetric to qSetFieldWidth. Your solution is certainly effective!

        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