高度なリッチテキスト処理

大きなファイルの扱い

Qt ではテキスト処理に使用するファイルのサイズを制限していません。ほとんどの場合、これは問題になりません。しかし、特に大きなファイルの場合、アプリケーションが応答しなくなったり、メモリ不足になったりすることがあります。読み込めるファイルのサイズは、ハードウェアや、Qt やアプリケーションの実装に依存します。

この問題に直面した場合、以下の問題に対処することをお勧めします:

  • Qt は小さな段落をうまく処理するので、大きな段落を小さな段落に分割することを検討すべきです。また、一定の間隔で改行を挿入することもできます。この場合、QTextEdit の1つの大きな段落と同じように見えます。
  • maximumBlockCount() を使えば、QTextDocument のブロックの量を減らすことができます。QTextEdit に関する限り、ドキュメントはブロックの数だけ大きくなります。
  • テキスト編集にテキストを追加する場合、編集ブロック内に追加するのが有利です(以下の例を参照)。その結果、テキスト編集は文書構造全体を一度に構築する必要がなくなります。

リストの中から後者のテクニックの例を挙げます。ここではテキスト編集が表示されているものとします。

textEdit.show();

textCursor.beginEditBlock();

for (int i = 0; i < 1000; ++i) {
    textCursor.insertBlock();
    textCursor.insertText(paragraphText.at(i));
}

textCursor.endEditBlock();

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.