QString::mid() always returns the same result

Viewed 388

This function should split a QString by (almost) equal fragments:

QStringList splitCell(const QString& cell) const
{
    QStringList result;

    const int currentSize = cell.size();
    const int fragmentCount = currentSize / c_maxCellSize + (currentSize % c_maxCellSize ? 1 : 0); // c_maxCellSize = 32758
    const int fragmentSize = currentSize / fragmentCount + (currentSize % fragmentCount ? 1 : 0);

    for (int fragment = 0; fragment < fragmentCount; ++fragment)
    {
        QString currentFragment = cell.mid(fragmentSize * fragment, fragmentSize);
        result << currentFragment;
    }

    return result;
}

But if fragmentCount > 1 then currentFragment is always the same in every iteration. What's wrong? P.S. The cell string may be large (up to 100K symbols)

1 Answers
Related