Reading from a file realized with Qt/MinGW is slower than in Delphi 7



  • I need to read a simple structured file.
    This is an algorithm
    @
    bool Reader::readTo(void *dest)
    {
    if (!file->open(QIODevice::ReadOnly) || !dest) return false;
    QTextStream in(file);
    Data *data = (Data *) dest;

    QString line = "";
    QString datetime;
    Point *point;
    int size = 0;
    data->clear();
    while ((!in.atEnd()) || !line.contains("//STOP", Qt::CaseInsensitive)){
    line = in.readLine();
    size += line.size();
    int index = line.indexOf('[');
    if (index != -1) {
    datetime = line.mid(0, index);
    point = new Point();
    point->date = QDateTime::fromString(datetime, "<yy/MM/dd>(hh:mm:ss:z)");
    point->date = point->date.addYears(100);
    QStringList data = line.mid(index + 1, line.count() - index - 2).split(" ");

    for (int i = 0; i < count; i++)
    {
    point.data.append(data.at(i).toInt());
    }
    data->append(*point);
    delete point;
    }
    }
    file->close();
    return true;
    }
    @

    So, that algorithm is 20% slower than analogue in Delphi. I noticed that the most expensive operation is data.at(i).toInt(). Maybe I compiled Qt wrong? Any ideas?


  • Moderators

    Could you please mark up your code as code? Thanks!



  • Sorry about code, it is my first post, but what can be wrong with algorithm?

    this is example of the file:

    <10/03/10>(06:11:24:00)[1245 1245 1248 1237 1259 2107 2166 2125 1261 2241]

    thanks for help



  • I think this becouse you using QTextStream and QString classes. They convert string to Unicode each time when you read from file. Try use QFile and QByteArray instead.



  • Yes, the problem was in converting to Unicode. Thank you, Sabrog.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.