이 페이지에서

고급 서식 텍스트 처리

대용량 파일 처리

Qt는 텍스트 처리에 사용되는 파일의 크기를 제한하지 않습니다. 대부분의 경우 이는 문제가 되지 않습니다. 그러나 특히 대용량 파일의 경우, 애플리케이션이 응답하지 않거나 메모리가 부족해지는 현상이 발생할 수 있습니다. 로드할 수 있는 파일의 크기는 하드웨어와 Qt 및 사용자 애플리케이션의 구현 방식에 따라 달라집니다.

이러한 문제가 발생하면 다음 사항을 해결하는 것이 좋습니다:

  • Qt XML은 짧은 단락을 더 잘 처리하므로, 큰 단락을 더 작은 단락으로 나누는 것을 고려해야 합니다. 또한 일정한 간격으로 줄 바꿈을 삽입할 수 있는데, 이는 QTextEdit 에서 하나의 큰 단락과 동일하게 표시됩니다.
  • ` QTextDocument ` 내의 블록 수를 ` maximumBlockCount()`를 사용하여 줄일 수 있습니다. ` QTextEdit `의 관점에서 볼 때, 문서의 크기는 블록의 수만큼만 됩니다.
  • 텍스트 편집창에 텍스트를 추가할 때는 편집 블록(edit block) 내에 추가하는 것이 유리합니다(아래 예시 참조). 그 결과, 텍스트 편집창이 문서 구조 전체를 한 번에 구축할 필요가 없습니다.

목록에서 후자의 기법에 대한 예시를 들어보겠습니다. 텍스트 편집기가 표시되어 있다고 가정합니다.

textEdit.show();

textCursor.beginEditBlock();

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

textCursor.endEditBlock();

© 2026 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.