Results 1 to 4 of 4

Thread: Find function in Qt ?

  1. #1
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Find function in Qt ?

    Hi folks,

    Is there any function in Qt to find a string in a file.

    Or any other solution to get a needed text instead of reading line by line.

    Thanks,
    -

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Find function in Qt ?

    Qt Code:
    1. QFile f("somefile");
    2. f.open(QIODevice::ReadOnly);
    3. QString data = f.readAll();
    4. int i = data.indexOf("Find me");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Find function in Qt ?

    Thank you very much wysota.

    Could you tell me how to remove a particular line from the file,
    or replace that line by some other line, completely.

    Thanks
    -

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Find function in Qt ?

    Quote Originally Posted by npc
    how to remove a particular line from the file, or replace that line by some other line, completely.
    Then it's probably easiest to simply read line by line, for example append all read (and possibly modified/replaced) lines to a string(list) and then write it back to the file. You cannot remove data from the middle of a file. You have to read it all, modify, and then re-write the file.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    npc (9th May 2006)

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  4. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  5. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33

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.