Results 1 to 9 of 9

Thread: Find and replace a string in file using QFile class in QT

  1. #1
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Find and replace a string in file using QFile class in QT

    Hi all,

    I am able to read data from the file and stored it in QString , now i want to find and replace a string in that file.
    Can one help me and give a solution.



    Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Find and replace a string in file using QFile class in QT

    There is no magic bullet function to "find and replace a string in that file". QString::replace() seems obvious enough though.

    There is a small thing in every copy of Qt called Assistant. Assistant contains overview, reference documentation and examples you might find informative.

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


  4. #3
    Join Date
    May 2013
    Posts
    45
    Thanks
    6
    Thanked 6 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Find and replace a string in file using QFile class in QT

    Quote Originally Posted by ChrisW67 View Post
    There is no magic bullet function to "find and replace a string in that file". QString::replace() seems obvious enough though.

    There is a small thing in every copy of Qt called Assistant. Assistant contains overview, reference documentation and examples you might find informative.
    Yes, we are spoiled with QT documentation

  5. #4
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Find and replace a string in file using QFile class in QT

    Hi all,

    I have append my scratch code below:

    QFile file("/root/vodo");
    if (!file.open(QIODevice::ReadWrite| QIODevice::Text))
    return;

    QTextStream in(&file);
    QString line = in.readAll();
    qDebug()<<"Text file Data..>>"<<line;
    file.close();

    Output of the above code:

    Information datum
    File exist

    I want to replace " datum " to "data"

    Kindly any one help me.

    Thanks in advance.

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Find and replace a string in file using QFile class in QT

    You already have the answer. Try to help yourself.

  7. #6
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Find and replace a string in file using QFile class in QT

    Hi all,

    Thanks for your support and encourage me , i have solved the issue of replacing string in file .Tanks to all

    Now i want to create qrcode of converting string to qrcode and convert image to qrcode

    Can any one help me

    Thanks in advance.

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Find and replace a string in file using QFile class in QT

    Can any one help me
    Yes, start by not double posting.. then you only have to look in one place for an answer..

  9. #8
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Find and replace a string in file using QFile class in QT

    Hi,

    I have posted in separately for QRcode related , but i'm not get the solution that's why i have double posting .


    Thanks in advance.

  10. #9
    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: Find and replace a string in file using QFile class in QT

    Quote Originally Posted by mania View Post
    I have posted in separately for QRcode related , but i'm not get the solution that's why i have double posting .
    Double posting does nothing to help in that case.
    Actually it is the opposite of helpful because double postings are extremely annoying.They require people to read the same things multiple times, taking away their time to read a really new question. So the effect is that they henceforth ignore all postings of known double posters.

    That is if they are lucky. If the annoyed person is a moderator or admin the double poster will likely get warned, on repetition of the offence bannded.

    In other words: double posting hurts your cause.

    Cheers,
    _

Similar Threads

  1. Reading file using QFile class
    By mania in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2013, 16:12
  2. Replies: 1
    Last Post: 28th May 2012, 15:06
  3. How to replace string in qt
    By lekhrajdeshmukh in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2011, 08:19
  4. [java] string.replace
    By mickey in forum General Programming
    Replies: 3
    Last Post: 7th September 2010, 07:04
  5. Replies: 3
    Last Post: 3rd May 2009, 08:58

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.