QTfrontend/util/namegen.cpp
changeset 8110 9f5fe3fc9d16
parent 8049 133e22b5c410
child 8126 5bfa1b2025d6
child 9080 9b42757d7e71
--- a/QTfrontend/util/namegen.cpp	Fri Nov 23 13:08:50 2012 +0400
+++ b/QTfrontend/util/namegen.cpp	Fri Nov 23 16:16:02 2012 +0400
@@ -125,22 +125,21 @@
     QStringList list;
 
     // find .txt to load the names from
-    QFile * file = new QFile(QString("physfs://Names/%1.txt").arg(filename));
+    QFile file(QString("physfs://Names/%1.txt").arg(filename));
 
-    if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
+    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
     {
-        QTextStream in(file);
-        while (!in.atEnd())
+        QTextStream in(&file);
+        QString line;
+        do
         {
-            QString line = in.readLine();
+            line = in.readLine();
+
             if(!line.isEmpty())
                 list.append(line);
-        }
+        } while (!line.isNull());
     }
 
-    // this QFile isn't needed any further
-    delete file;
-
     if (list.size() == 0)
         list.append(filename);
 
@@ -153,22 +152,21 @@
     QStringList list;
 
     // find .cfg to load the dicts from
-    QFile * file = new QFile(QString("physfs://Names/%1.cfg").arg(hatname));
+    QFile file(QString("physfs://Names/%1.cfg").arg(hatname));
 
-    if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
+    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
     {
-        QTextStream in(file);
-        while (!in.atEnd())
+        QTextStream in(&file);
+        QString line;
+        do
         {
-            QString line = in.readLine();
+            line = in.readLine();
+
             if(!line.isEmpty())
                 list.append(line);
-        }
+        } while (!line.isNull());
     }
 
-    // this QFile isn't needed any further
-    delete file;
-
     if (list.size() == 0)
         list.append(QString("generic"));