Results 1 to 6 of 6

Thread: Parsing ASCII model files with QT

  1. #1
    Join Date
    Jul 2015
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Parsing ASCII model files with QT

    Hello and thank you for your time. I am new to C++ and QT. I need to parse an ASCII model file which contains multiple sub-circuits and multiple models within the sub-circuits. The sub-circuits are denoted by lines beginning with ".subckt", followed by sub-circuit parameters, followed by the models inside them, numbered sequentially and beginning with ".model some_name.1". I need to leave the entire sub-circuit as is. After the end of the sub-circuit, I need to append everything in the sub-circuit until the first model, then append the first model and remove the remaining models, and repeat this process for all of the models within the sub-circuit. For example, if I have a sub-circuit with two models in it, the end result would be three total sub-circuits, the original containing both models, and two new sub-circuits each containing one of the models.
    I have been trying to solve this using QRegExp, cap() and reading the files line by line, but one of the problems I have encountered is that because the ".subckt" and ".model" are on separate lines, it does not capture everything after ".subckt" until ".model", it captures everything on the same line as ".subckt". Also the number of models within each sub-circuit is not constant, so I need a way to create as many new sub-circuits as there are models in a given sub-circuit.
    Is QRegExp and cap() the way to go with this? Also, I need help with creating the loop or function that can count the number of models in a sub-circuit and create that number of new sub-circuits. Any help and suggestions are greatly appreciated. Thank you for you time and help.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parsing ASCII model files with QT

    Maybe it would be better to parse the file into data structures, then manipulate these structures and then write the data out to a file again.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    ar_jym (30th July 2015)

  4. #3
    Join Date
    Jul 2015
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Parsing ASCII model files with QT

    Thank you for your reply. How would I parse the file into data structures? Would I write my own parser or are there features for that?

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parsing ASCII model files with QT

    There are several ways to write a parser.

    If the format is line oriented you can read lines and then parse each line depending on what you are expecting at the moment.

    Cheers,
    _

  6. #5
    Join Date
    Jul 2015
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Parsing ASCII model files with QT

    Can you give me an example of how I can do this? I am using QRegExp to capture lines and then put them in a QStringList. What type of data structure do you mean and how can I use the data in the structures later? Thank you.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parsing ASCII model files with QT

    That depends on your data.
    You write that you have sub circuits and models.
    Find out which data they can hold and you arrive at the fields for these datastructures.
    You can of course also just keep the strings.

    The whole point is to make it easier for you to work on that data given your requirements.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 21st January 2011, 11:50
  2. Replies: 3
    Last Post: 6th May 2010, 04:02
  3. read ascii files with different column counts
    By pospiech in forum Qt Programming
    Replies: 5
    Last Post: 6th November 2009, 12:42
  4. Parsing Files
    By JayJay in forum Qt Programming
    Replies: 13
    Last Post: 20th August 2007, 19:01
  5. Parsing of Text files in Qt
    By shailesh in forum Qt Programming
    Replies: 3
    Last Post: 21st April 2006, 15:35

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.