本文整理汇总了C++中QFile::readLine方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::readLine方法的具体用法?C++ QFile::readLine怎么用?C++ QFile::readLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::readLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadLabels
int loadLabels(const char* fn) {
int res = 1;
QString path(fn);
QString line;
QString name;
QStringList arr;
QFile file;
xAdr xadr;
if (path.isEmpty())
path = QFileDialog::getOpenFileName(NULL, "Load SJASM labels");
if (path.isEmpty()) {
res = 0; // no file specified
} else {
conf.labels.clear();
file.setFileName(path);
if (file.open(QFile::ReadOnly)) {
while(!file.atEnd()) {
line = file.readLine();
arr = line.split(QRegExp("[: \r\n]"),QString::SkipEmptyParts);
if (arr.size() > 2) {
xadr.type = MEM_RAM;
xadr.bank = arr.at(0).toInt(NULL,16);
xadr.adr = arr.at(1).toInt(NULL,16) & 0x3fff;
xadr.abs = (xadr.bank << 14) | xadr.adr;
name = arr.at(2);
switch (xadr.bank) {
case 0xff:
xadr.type = MEM_ROM;
xadr.bank = -1;
break;
case 0x05:
xadr.adr |= 0x4000;
break;
case 0x02:
xadr.adr |= 0x8000;
break;
default:
xadr.adr |= 0xc000;
break;
}
if (xadr.bank > 0)
xadr.bank = xadr.abs >> 8;
conf.labels[name] = xadr;
}
}
} else {
示例2: while
vector<QStringList> MainWindow::getFromCsv(QString path){
vector<QStringList> fileDate;
QFile file;
file.setFileName(path);
file.open(QIODevice::ReadOnly);
cout<<"FilePath - "<<path.toUtf8().constData()<<endl;
while(!file.atEnd()){
QString str= file.readLine();
str.replace(',','.');
QStringList oneString=str.split(';');
cout<<str.toUtf8().constData()<<endl;
fileDate.push_back(oneString);
}
file.close();
return fileDate;
}
示例3: read_line
bool WorldFile::read_line(QFile & file, double & value)
{
char buffer[256];
if (-1 == file.readLine(buffer, sizeof (buffer))) {
qDebug() << SG_PREFIX_E << "Failed to read line from file" << file.errorString();
return false;
}
bool ok = false;
value = QString(buffer).toDouble(&ok);
if (!ok) {
qDebug() << SG_PREFIX_E << "Failed to convert" << buffer << "to double";
return false;
}
qDebug() << SG_PREFIX_I << "Read value" << value;
return true;
}
示例4: init
void WordList::init(const QString locale) {
//Create 'Binary Tree'
//QFile in(":/words.dict");//Assumed to be in alphabetical order already
QFile in;
if (locale=="fr") {
in.setFileName(":/liste_fr.txt");
} else {
in.setFileName(":/wordlist2.txt");
}
bool opened = in.open(QFile::Text | QFile::ReadOnly);
Q_ASSERT(opened);
int c=0;
char cur[LEN_MAX];
char curIdx[2];//Assumed all words have at least 2 letters
curIdx[0] = ' ';
curIdx[1] = ' ';
m_words.clear();
while(in.readLine(cur,LEN_MAX) > 0) {
//qDebug() << QString(cur).toLower().trimmed();
if(cur[0]=='\n' || cur[0]=='\0')
continue;
m_words << QString(cur).toLower().trimmed();
sprintf(dict[c],"%s", cur);
if(curIdx[0] < cur[0]) { //Assumed each of the 26 letters starts at least one word
curIdx[0] = cur[0];
curIdx[1] = 'a';
idx[(curIdx[0]-'a') * 26] = c;
}
while(curIdx[1] < cur[1]) {
curIdx[1]++;
Q_ASSERT(curIdx[1] >= 'a' && curIdx[1] <= 'z');
idx[(curIdx[0]-'a') * 26 + (curIdx[1] - 'a')] = c;
}
c++;
}
numWords = c;
Q_ASSERT(m_words.count() == c);//Assumed no duplicates
in.close();
}
示例5: qfile
dlgAboutIqr::dlgAboutIqr(QWidget* parent) : QDialog(parent) {
setupUi(this);
#ifdef _WINDOWS
char *cwd = getcwd (NULL, 0);
string strAppDir = cwd;
#else
string strAppDir;
char * pcIQR_HOME = NULL;
pcIQR_HOME = getenv ("IQR_HOME");
if (pcIQR_HOME!=NULL){
strAppDir = pcIQR_HOME;
} else {
strAppDir = "/usr/lib/iqr/";
}
#endif
QString qstrVersion = "";
QString qstrFilename = string(strAppDir + "/iqr.version").c_str();
QFile qfile (qstrFilename);
if(qfile.exists()){
qfile.open( QIODevice::ReadOnly);
char buf[1024];
qfile.readLine(buf, sizeof(buf) );
qfile.close();
qtxteditVersion->setText(buf );
} else {
cerr << "iqr.version not found" << endl;
}
QString qstrMovieFile = string(strAppDir + "/iqr-logo-lg.gif").c_str();
qlblMovie->setMovie(new QMovie (qstrMovieFile));
if(qlblMovie->movie()!=NULL){
qlblMovie->movie()->setPaused(false);
}
}
示例6: QFile
void
Animxmlparser::searchForVersion ()
{
QFile * f = new QFile (m_traceFileName);
if (f->open (QIODevice::ReadOnly | QIODevice::Text))
{
QString firstLine = QString (f->readLine ());
int startIndex = 0;
int endIndex = 0;
QString versionField = VERSION_FIELD_DEFAULT;
startIndex = firstLine.indexOf (versionField);
endIndex = firstLine.lastIndexOf ("\"");
if ((startIndex != -1) && (endIndex > startIndex))
{
int adjustedStartIndex = startIndex + versionField.length ();
QString v = firstLine.mid (adjustedStartIndex, endIndex-adjustedStartIndex);
m_version = v.toDouble ();
}
f->close ();
delete f;
}
}
示例7: loadKeywords
QStringList SQLTextEdit::loadKeywords(const QString &driver)
{
QFile listfile;
if (driver == "QSQLITE")
listfile.setFileName(":/txt/keywords/sqlite-keywords.txt");
else if (driver == "QMYSQL")
listfile.setFileName(":/txt/keywords/mysql-keywords.txt");
else if (driver == "QPSQL")
listfile.setFileName(":/txt/keywords/postgresql-keywords.txt");
else
return QStringList();
listfile.open(QIODevice::ReadOnly);
QStringList list;
QString line;
while (!(line = listfile.readLine()).isEmpty()) {
list << line.trimmed();
}
return list;
}
示例8: main
int main(int argc, char **argv)
{
#if !defined(Q_OS_WIN)
// QtService stores service settings in SystemScope, which normally require root privileges.
// To allow testing this example as non-root, we change the directory of the SystemScope settings file.
QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, QDir::tempPath());
qWarning("(Example uses dummy settings file: %s/QtSoftware.conf)", QDir::tempPath().toLatin1().constData());
#endif
int result = processArgs(argc, argv);
if (QString::fromLocal8Bit(argv[argc - 1]) == QLatin1String("-w") ||
QString::fromLocal8Bit(argv[argc - 1]) == QLatin1String("-wait")) {
printf("\nPress Enter to continue...");
QFile input;
input.open(stdin, QIODevice::ReadOnly);
input.readLine();
printf("\n");
}
return result;
}
示例9: getSourceCodeStringsNumber
void Dialog::getSourceCodeStringsNumber() {
QString str;
QFile srcFile;
for (ptrdiff_t i=0; i<files->count(); i++) {
srcFile.setFileName(files->at(i));
srcFile.open(QIODevice::ReadOnly);
while (!srcFile.atEnd()) {
str = srcFile.readLine().trimmed();
if ( (!str.isEmpty()) && (!str.isNull()) ) {
lines++;
}
}
srcFile.close();
}
}
示例10: update
void BasicMixedProviderPrivate::update(const QString &path, QMap <QString, QString> *data)
{
data->clear();
QFile file (path);
if (!file.open(QIODevice::ReadOnly)) {
return;
}
while (!file.atEnd()) {
QString line = file.readLine();
QStringList lineSplitted = line.split(";");
if (lineSplitted.count() == 1) {
data->insert(lineSplitted.at(0).trimmed(), QString());
}
if (lineSplitted.count() == 2) {
data->insert(lineSplitted.at(0).trimmed(), lineSplitted.at(1).trimmed());
}
}
file.close();
}
示例11: on_actionLoad_cost_grid_triggered
void TsunamiEvacModel::on_actionLoad_cost_grid_triggered()
{
QString fileName;
fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), QDir::homePath(), tr("Image Files (*.csv)"));
QList<QStringList> myMat;
QFile file;
file.setFileName(fileName);
if(file.open(QIODevice::ReadOnly))
setStatus("File opened");
else
setStatus("Could not open file");
while (!file.atEnd()){
QByteArray line = file.readLine();
QStringList temp;
for(int i = 0; i < line.split(',').size(); i++)
temp.append(line.split(',').at(i));
myMat.append(temp);
}
QString temp;
delete myGrid;
myGrid = new Grid(myMat.size(),myMat.at(1).size(),this);
for(int i = 0; i < myMat.size(); i++){
for(int j = 0; j < myMat.at(i).size(); j++){
myGrid->setValue(i,j,myMat.at(i).at(j).toInt());
temp.append(myMat.at(i).at(j));
temp.append(" ");
}
temp.append("\n");
}
ui->textBrowser->append(temp);
}
示例12: load
void DictModel::load(QFile& file)
{
beginResetModel();
m_dicts.clear();
QByteArray bytes;
while (!(bytes = file.readLine()).isEmpty()) {
QString line = QString::fromUtf8(bytes).trimmed();
QStringList items = line.split(",");
if (items.size() < m_requiredKeys.size()) {
continue;
}
bool failed = false;
QMap<QString, QString> dict;
Q_FOREACH(const QString& item, items) {
if (!item.contains('=')) {
failed = true;
break;
}
QString key = item.section('=', 0, 0);
QString value = item.section('=', 1, -1);
if (!m_requiredKeys.contains(key)) {
continue;
}
dict[key] = value;
}
if (!failed && m_requiredKeys.size() == dict.size()) {
m_dicts << dict;
}
}
endResetModel();
}
示例13: getRecipe
void CLoaderRecipe::getRecipe()
{
QFile *file;
QDir dir("recipe");
if (!dir.exists())
qWarning("Cannot find the example directory");
dir.setFilter(QDir::Files);
QFileInfoList list = dir.entryInfoList();
for (int loop = 0; loop < list.size(); ++loop)
{
QFileInfo fileInfo = list.at(loop);
file = new QFile(fileInfo.filePath());
file->open(QIODevice::ReadOnly | QIODevice::Text);
QString line;
while (!file->atEnd())
{
line = file->readLine();
QStringList lineList = line.split(";");
if (lineList.size() == 6)
recipeList.append(new CRecipe(lineList[0], lineList[1], lineList[2], lineList[3], lineList[4], lineList[5].remove("\n"), fileInfo.filePath()));
}
delete file;
}
}
示例14: localMachineId
QByteArray FcitxQtConnectionPrivate::localMachineId()
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
return QDBusConnection::localMachineId();
#else
QFile file1("/var/lib/dbus/machine-id");
QFile file2("/etc/machine-id");
QFile* fileToRead = NULL;
if (file1.open(QIODevice::ReadOnly)) {
fileToRead = &file1;
}
else if (file2.open(QIODevice::ReadOnly)) {
fileToRead = &file2;
}
if (fileToRead) {
QByteArray result = fileToRead->readLine(1024);
fileToRead->close();
result = result.trimmed();
if (!result.isEmpty())
return result;
}
return "machine-id";
#endif
}
示例15: getcpu
void MainWindow::getcpu()
{
QString tempStr; //读取文件信息字符串
QFile tempFile; //用于打开系统文件
int pos; //读取文件的位置
tempFile.setFileName("/proc/cpuinfo"); //打开CPU信息文件
if ( !tempFile.open(QIODevice::ReadOnly) )
{
QMessageBox::warning(this, tr("warning"), tr("The cpuinfo file can not open!"), QMessageBox::Yes);
return;
}
for(int i=0;i<10;i++)
{
tempStr = tempFile.readLine();
pos = tempStr.indexOf("model name");
if (pos != -1)
{
pos += 13; //跳过前面的"model name:"所占用的字符
QString *cpu_name = new QString( tempStr.mid(pos, tempStr.length()-13) );
fg5=cpu_name->contains("i5");
fg7=cpu_name->contains("i7");
}
}
}