QTfrontend/util/namegen.cpp
branchflibqtfrontend
changeset 8126 5bfa1b2025d6
parent 8103 c247346d296f
parent 8110 9f5fe3fc9d16
--- a/QTfrontend/util/namegen.cpp	Mon Nov 26 00:06:42 2012 +0400
+++ b/QTfrontend/util/namegen.cpp	Mon Nov 26 00:09:54 2012 +0400
@@ -117,22 +117,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);
 
@@ -145,22 +144,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"));