Search code examples
qtqtablewidgetqlist

How to can append the value from txt file to the Qlist


How I can to insert the value from txt file in to the Qlist...

QList<QString> list_StRead;
list_StRead.insert();

I can sorting txt file ... its mean that my file is a line by line. than after the insert to the Qlist I want to write in to Qtabelewidget. How I must to do?? u must to be completely understand. see the img file

enter image description here

tnx for all....


Solution

  • Here is the pseudo code. Please try it. (Not tested, code written in notepad. excuse me any syntax errors).

    //Your list
    QList<QString> list_StRead;
    
    //Text stream object read data and insert in list.
    QTextStream in(&file);
       while (!in.atEnd())
       {
          QString line = in.readLine(); //read one line at a time
          list_StRead.push_back(line);
       }
    
    
    //loop your list 
    for(int i =0; i<list_StRead.size(); i++)
    {
    
    //Add by create your tablewidget item and append it.
    YourTableWidget->setItem(rowNumber,colNumber,new  QTableWidgetItem(list_StRead.at(i)))
    
    
    }