Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get lines from a file using editText

How to get lines from a file using editText

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 324 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LordHomie
    wrote on 2 Dec 2019, 19:14 last edited by
    #1

    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()); 
     }
    
    J 1 Reply Last reply 2 Dec 2019, 19:22
    0
    • L LordHomie
      2 Dec 2019, 19:14

      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()); 
       }
      
      J Offline
      J Offline
      JonB
      wrote on 2 Dec 2019, 19:22 last edited by
      #2

      @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?

      L 1 Reply Last reply 2 Dec 2019, 19:49
      2
      • J JonB
        2 Dec 2019, 19:22

        @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?

        L Offline
        L Offline
        LordHomie
        wrote on 2 Dec 2019, 19:49 last edited by LordHomie 12 Feb 2019, 19:50
        #3

        @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

        J 1 Reply Last reply 2 Dec 2019, 20:03
        0
        • L LordHomie
          2 Dec 2019, 19:49

          @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

          J Offline
          J Offline
          JonB
          wrote on 2 Dec 2019, 20:03 last edited by JonB 12 Feb 2019, 20:06
          #4

          @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?

          1 Reply Last reply
          5

          1/4

          2 Dec 2019, 19:14

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved