Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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::on_showlines_clicked()
    {
         Quizlet quizlet;  //creating an object of class Quizlet
    
        //quizlet.ReadAllWords(); //calling the function ReadAllWords
    
        ui->textEdit->setText(quizlet.ReadAllWords()); 
     }


  • @LordHomie said in How to get lines from a file using editText:

    but iam facing problems in calling the ReadAllWords function and setText!

    Always helps if you say what problems, or do you think we should be able to guess?



  • @JonB said in How to get lines from a file using editText:

    am facing problems in calling the ReadAllWords function and setText!

    LoL, i think i mentioned already.

    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



  • @LordHomie

    LoL, i think i mentioned already.

    You said there was a problem, but nothing about what it is. Nothing like an error message.

    So if it's

    vector<string> Quizlet::ReadAllWords()
    

    presumably you need to convert that list of strings into something compatible with setText(const QString &)? Maybe you want to rejoin the lines with \n?


Log in to reply