Results 1 to 2 of 2

Thread: How to get lines from a file using editText

  1. #1

    Default How to get lines from a file using editText

    Hello everyone!

    here, iam trying to read all the lines from my file into qt textEdit but iam facing problems in calling the ReadAllWords function and setText!

    here is my code, i think iam close, because i did it a long time ago but i totally forgot.
    Thanks!


    void delete1:n_showlines_clicked()
    {
    Quizlet quizlet; //creating an object of class Quizlet

    //quizlet.ReadAllWords(); //calling the function ReadAllWords

    ui->textEdit->setText(quizlet.ReadAllWords());
    }

    well, this is my code for ReadAllWords function to print all the lines from the file:


    vector<string> Quizlet::ReadAllWords() {

    // File pointer

    fstream fin;

    fin.open("words.txt", ios::in);

    vector <string> rows;

    string line, word, temp;

    while (getline(fin, line)) {

    rows.push_back(line);

    stringstream s(line);

    }
    return rows;

    }

    and in another source file i want to call the ReafAllFunction into editText,
    i hope this helps

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get lines from a file using editText

    Hi,
    - QTextEdit::setText() does not accept a vector of std::strings. You need to create a QString from the strings in your vector.
    - The line stringstream s(line); does not do anything. The stream is destroyed directly after it was created when the end of the while loop is reached.

    Ginsengelf

Similar Threads

  1. Read the last three lines from a file
    By sangee in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2012, 11:46
  2. Read data from EditText from Javascript
    By regish.enfin in forum Qt Quick
    Replies: 1
    Last Post: 9th September 2011, 12:38
  3. read from file two lines
    By mmm286 in forum Newbie
    Replies: 6
    Last Post: 26th October 2009, 13:42
  4. Remove Duplicate Lines in a file
    By nmuntz in forum Qt Programming
    Replies: 4
    Last Post: 12th January 2009, 01:04
  5. How to change Text colour in EditText?
    By phillip_Qt in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2008, 09:48

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.