Results 1 to 4 of 4

Thread: Copy a File with QT

  1. #1
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Copy a File with QT

    Hello Guys,

    I beginned programming with c++ a few month ago and since two weeks with qut... So im a newby :-)

    I have written a source code with stl and i want to do the same thing with qt cause of the many options of qt library.

    The Programm copy a file line for line... It would be better if its copy char for char, but i didn't find a good algorithm for that...

    ...So long I have two questions!

    How can I programm this in QT (maybe somebody are so nice and write the code new ) that it read only char for char and not line for line . My other question is, is how i have to programm that, it makes a \n before the keyword i give him... I tryied in my code but without successs....

    My english is also not good, so excuse me :-)

    Qt Code:
    1. std::ifstream read(directory1);
    2. std::ofstream write( "Keyword.lst" );
    3.  
    4. std::string line;
    5.  
    6. while (std::getline( read, line ) && line!="*NET*");
    7.  
    8. write <<"*Automatic*"<<std::endl<<std::endl;
    9. write <<"*Test*"<<std::endl<<std::endl;
    10.  
    11. while ( !read.eof() )
    12. {
    13. std::getline(read, line);
    14. if(line == "*keyword*"){
    15. write <<' \n';
    16. write << line<<std::endl;
    17. }
    18. else
    19. write << line<<std::endl;
    20. }
    21.  
    22. write.close();
    23. read.close();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Copy a File with QT

    Take a look at QFile docs. There's an example of reading a file line by line in the detailed description.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Copy a File with QT

    But that is what i dont need, sorry maybe i impressed myself wrong

    I want a reading char for char!

  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: Copy a File with QT

    Ok, I'll give you a hint. QFile inherits QIODevice.
    J-P Nurmi

Similar Threads

  1. Copy a File over the Network
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 17th June 2008, 12:36
  2. copy and run a .exe file in another system
    By sabeesh in forum Installation and Deployment
    Replies: 3
    Last Post: 22nd August 2007, 10:05
  3. Copy a file?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 21:05
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Replies: 4
    Last Post: 24th February 2006, 10:30

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.