Qt - reading from a text file

后端 未结 1 1176
醉酒成梦
醉酒成梦 2020-12-28 16:07

I have a table view with three columns; I have just passed to write into text file using this code

QFile file(\"/home/hamad/lesson11.txt\");
if(!file.open(QI         


        
相关标签:
1条回答
  • 2020-12-28 16:27

    You have to replace string line

    QString line = in.readLine();
    

    into while:

    QFile file("/home/hamad/lesson11.txt");
    if(!file.open(QIODevice::ReadOnly)) {
        QMessageBox::information(0, "error", file.errorString());
    }
    
    QTextStream in(&file);
    
    while(!in.atEnd()) {
        QString line = in.readLine();    
        QStringList fields = line.split(",");    
        model->appendRow(fields);    
    }
    
    file.close();
    
    0 讨论(0)
提交回复
热议问题