Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-119717

给QGraphicsTextItem设置文本居中出现内存泄漏 Google translate: Memory leak occurs when setting text center for QGraphicsTextItem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P1: Critical
    • None
    • 5.14, 6.6.0
    • Widgets: GraphicsView
    • None
    • Windows

    Description

      我的项目通过查找QGraphicsTextItem设置文字居中方式,查找到了链接https://blog.csdn.net/qq_44365088/article/details/106907000

      这段代码添加到项目的两年后,在前几天的一次测试时,我发现项目程序出现了内存泄漏,经过排查我发现是反复调用了这段代码的原因。

      然后我写了一个模拟程序,我只调用了简单的set函数,内存却在不断增加。

      Google translate:
      In my project, I set the text centering method by looking for QGraphicsTextItem, and found the link https://blog.csdn.net/qq_44365088/article/details/106907000.

      Two years after this code was added to the project, during a test a few days ago, I discovered that there was a memory leak in the project program. After investigation, I found that the reason was that this code was repeatedly called.

      Then I wrote a simulation program. I only called a simple set function, but the memory kept increasing.

      #include <QApplication>
      #include <QTextBlockFormat>
      #include <QTextCursor>
      #include <QGraphicsPixmapItem>
      int main(int argc, char *argv[]) {
          QApplication a(argc, argv);
          QGraphicsTextItem* item = new QGraphicsTextItem;
          item->setPlainText("qfhqiwhfoqwhfqiwhfoqf");
          while(1) {
               QTextBlockFormat format;
               format.setAlignment(Qt::AlignRight);
               QTextCursor cursor = item->textCursor();         
               cursor.setBlockFormat(format);
               item->setTextCursor(cursor); 
          }
          return a.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bibr Andreas Aardal Hanssen
            czh 泽豪 陈
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes