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
Forum Updated to NodeBB v4.3 + New Features

How to get lines from a file using editText

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 359 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.
  • LordHomieL Offline
    LordHomieL Offline
    LordHomie
    wrote on 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()); 
     }
    
    JonBJ 1 Reply Last reply
    0
    • LordHomieL LordHomie

      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()); 
       }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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?

      LordHomieL 1 Reply Last reply
      2
      • JonBJ JonB

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

        LordHomieL Offline
        LordHomieL Offline
        LordHomie
        wrote on last edited by LordHomie
        #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

        JonBJ 1 Reply Last reply
        0
        • LordHomieL LordHomie

          @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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #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

          • Login

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