mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 16:40:42 +08:00
Add 'readFile' function to Utl.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "SeerUtl.h"
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QDebug>
|
||||
#include <mutex>
|
||||
|
||||
@@ -506,5 +507,29 @@ namespace Seer {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool readFile (const QString& filename, QStringList& lines) {
|
||||
|
||||
// Empty the list
|
||||
lines = QStringList();
|
||||
|
||||
// Open the file.
|
||||
QFile file(filename);
|
||||
|
||||
if (file.open(QIODevice::ReadOnly) == false) {
|
||||
qDebug() << "Can't open:" << filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the file line-by-line and build up the string list.
|
||||
while (file.atEnd() == false) {
|
||||
lines.append(file.readLine());
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
// All good.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,5 +25,7 @@ namespace Seer {
|
||||
unsigned char ucharToAscii (unsigned char byte);
|
||||
|
||||
int typeBytes (const QString& type);
|
||||
|
||||
bool readFile (const QString& filename, QStringList& lines);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user