C++ (Qt)bool MainWindow::parserFile(QString path){ qDebug()<<"path = "<<path; QFile pFile(path); QString line; buffer = new QStringList; buffer->clear(); if(pFile.exists()){ if(!pFile.open(QIODevice::ReadWrite)){ qCritical()<<"file not open"; delete buffer; return false; } QByteArray ba = pFile.readAll(); qDebug()<<"ba = "<<ba; QString str; str.append(ba); qDebug()<<str; QStringList strList= str.split("\n"); qDebug()<<"strList = "<<strList.count(); for(int i = 0; i < strList.count(); i++){ QString s = strList.at(i); qDebug()<<"s = "<<s; } pFile.close(); return true; } qCritical()<<"file not exists load file"; delete buffer; return false;}
QByteArray ba = pFile.readAll();
qDebug()<<"ba.size() = "<<ba.size();
ba.size = 29114
C++ (Qt)// Если текстовый файл в UTF-8QTextCodec *codec = QTextCodec::codecForName( "UTF-8" );QString str = codec->toUnicode( ba ); QStringList strList= str.split("\n");qDebug()<<"strList = "<<strList.size();
C++ (Qt)bool MainWindow::parserFile(QString path){ qDebug()<<"path = "<<path; QFile pFile(path); QString line; buffer = new QStringList; buffer->clear(); if(pFile.exists()){ if(!pFile.open(QIODevice::ReadOnly)){ qCritical()<<"file not open"; delete buffer; return false; } QByteArray ba = pFile.readAll(); qDebug()<<"ba.size() = "<<ba.size(); QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QString str = codec->toUnicode(ba); //str.append(ba); qDebug()<<str; QStringList strList= str.split("\n"); qDebug()<<"strList = "<<strList.count(); for(int i = 0; i < strList.count(); i++){ QString s = strList.at(i); qDebug()<<"s = "<<s; } pFile.close(); return true; } qCritical()<<"file not exists load file"; delete buffer; return false;}
s = "