Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Reading from a file realized with Qt/MinGW is slower than in Delphi 7
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Brainstorm
5 Posts 3 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spirit
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Spirit
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sabrog
          wrote on last edited by
          #4

          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.

          QT - Apple QuickTime
          Qt - Nokia's Qt Development Frameworks
          Apple is a competitor of Nokia, so QT != Qt

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Spirit
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved