Results 1 to 2 of 2

Thread: Showing txt file details one by one

  1. #1
    Join Date
    Aug 2014
    Posts
    28
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Windows

    Unhappy Showing txt file details one by one

    i have txt file with this details :
    good
    bad
    hi
    now i want to show this words one by one after i click on Next button but with this code i only get "Good" text i mean when i click on next button doesnt show me other words. in overall my goal is when i click on next show me "good" word after i click it again show me "bad" after i click again show me "hi" here is my code with Qt 5.4

    Qt Code:
    1. void MainWindow::on_Next_clicked()
    2. {
    3. ui->ShowEn->clear();
    4. ifstream Sfile("E:\\en.txt");
    5. getData(Sfile);
    6. Sfile.close();
    7. }
    8. void MainWindow::getData(std::ifstream& myfile){
    9.  
    10. if(!myfile.eof())
    11. {
    12. std::string str;
    13. getline(myfile, str);
    14. ui->ShowEn->setText(QString::fromStdString(str));
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Showing txt file details one by one

    You are re-opening the file on every click of Next button, instead open the file only once and call getLine() on every Next click.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Technique to read file property details in Windows 7
    By astodolski in forum General Programming
    Replies: 3
    Last Post: 2nd March 2013, 08:37
  2. How to display Details of Audio File in QTreeView
    By owais_blore in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2012, 06:30
  3. Qt Assistant not showing my help file
    By armonge in forum Qt Tools
    Replies: 0
    Last Post: 7th October 2010, 07:47
  4. Replies: 1
    Last Post: 11th November 2009, 17:28
  5. Updating File attributes and it's summary details
    By senthilsp in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2009, 13:31

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.