Results 1 to 5 of 5

Thread: Remove Duplicate Lines in a file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Remove Duplicate Lines in a file

    Cryptographic hash is to complex. Here is something much simpler:

    Qt Code:
    1. f.open(QFile::ReadOnly|QFile::Text);
    2. QFile out;
    3. out.open(QFile::WriteOnly|QFile::Text);
    4. QSet<int> linesSeen;
    5. while(!f.atEnd()){
    6. QString s = f.readLine();
    7. int h = qHash(s);
    8. if(linesSeen.contains(h)) continue;
    9. linesSeen << h;
    10. out.write(s);
    11. }
    12. f.close();
    13. out.close();
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to wysota for this useful post:

    zeFree (23rd April 2013)

Similar Threads

  1. How to remove duplicate enteries from QStringList.
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 7th March 2019, 15:02
  2. remove node in xml file
    By mattia in forum Newbie
    Replies: 1
    Last Post: 6th March 2008, 13:25
  3. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  4. reading from a file
    By mickey in forum General Programming
    Replies: 32
    Last Post: 19th July 2007, 01:04
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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
  •  
Qt is a trademark of The Qt Company.