Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to detect memory errors in Qt based gui
Forum Updated to NodeBB v4.3 + New Features

How to detect memory errors in Qt based gui

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 4 Posters 5.0k Views 2 Watching
  • 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on 16 Jun 2016, 09:56 last edited by A Former User
    #1

    I have a Qt based gui and I am using qt.4.3.3 version and I wan to check the memory errors in GUI
    Could you let me know how to detect memory errors in GUI .

    and How integrrate the memory profiler in our tools

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 16 Jun 2016, 10:06 last edited by
      #2

      Sadly this is platform dependent, what OS are you on?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on 16 Jun 2016, 10:22 last edited by
        #3

        Red Hat Enterprise Linux Client release 5.8 (Tikanga)

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on 16 Jun 2016, 10:24 last edited by
          #4

          Red Hat Enterprise Linux Client release 5.8 (Tikanga

          I am also using C++ code to display the data in QTGUI

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VRonin
            wrote on 16 Jun 2016, 10:44 last edited by
            #5

            You can use valgrind then http://doc.qt.io/qtcreator/creator-valgrind-overview.html

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on 16 Jun 2016, 10:51 last edited by
              #6

              I assume I need to have a debug library of QT in my code

              J 1 Reply Last reply 16 Jun 2016, 11:25
              0
              • Q Qt Enthusiast
                16 Jun 2016, 10:51

                I assume I need to have a debug library of QT in my code

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 16 Jun 2016, 11:25 last edited by
                #7

                @Qt-Enthusiast Why? Do you want to debug Qt code?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  Qt Enthusiast
                  wrote on 16 Jun 2016, 12:05 last edited by
                  #8

                  there is crash coming in code QString code . I am want verify after my fix if my fix is without any memory errors

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    VRonin
                    wrote on 16 Jun 2016, 12:08 last edited by
                    #9

                    I'm quite confident there are no memory leaks in QString code. what seems to be the problem?

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    0
                    • Q Offline
                      Q Offline
                      Qt Enthusiast
                      wrote on 16 Jun 2016, 12:18 last edited by
                      #10

                      It is not memory leak . I am doing

                      if (FILE* fp = fopen(ofilename.toLatin1(), "r")) {
                      QTextStream ts(fp, QIODevice::ReadOnly);
                      setText(ts.readAll());
                      }

                      In my case the file size is 1.5G and the tool string because QString can take 1.5 G of memory /. Return type of readAll is QString

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JohanSolo
                        wrote on 16 Jun 2016, 12:25 last edited by JohanSolo
                        #11

                        A QString loaded from a 1.5 GB text file needs about 3 GB of memory, as the characters are stored in UTF-16, see the doc. On 32-bits system this almost exceeds the max addressable memory... Depending on how you allocate the QString instance, the consumed memory is far above what is allowed for an application. I therefore think it's normal you have troubles doing this. I would find surprising if you could do this without problems.

                        On a side note, I think you were told several times not to try to read such a huge file in one go...

                        `They did not know it was impossible, so they did it.'
                        -- Mark Twain

                        Q 1 Reply Last reply 17 Jun 2016, 06:00
                        2
                        • V Offline
                          V Offline
                          VRonin
                          wrote on 16 Jun 2016, 12:29 last edited by VRonin
                          #12
                          1. I'd use QFile instead of fopen()
                          2. make sure setText signature is setText(const QString&) and not setText(QString)
                          3. can you minimize the memory duplication replacing setText(ts.readAll()); with something like while(!ts.atEnd()) append(ts.readLine());

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          J 1 Reply Last reply 16 Jun 2016, 12:35
                          2
                          • J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 16 Jun 2016, 12:35 last edited by
                            #13

                            I'm wondering what the use-case is which requires to load 1.5GB text file?
                            For such amount of data memory mapped file I/O would be better.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            3
                            • V VRonin
                              16 Jun 2016, 12:29
                              1. I'd use QFile instead of fopen()
                              2. make sure setText signature is setText(const QString&) and not setText(QString)
                              3. can you minimize the memory duplication replacing setText(ts.readAll()); with something like while(!ts.atEnd()) append(ts.readLine());
                              J Offline
                              J Offline
                              JohanSolo
                              wrote on 16 Jun 2016, 12:35 last edited by
                              #14

                              @VRonin said:

                              1. make sure setText signature is setText(const QString&) and not setText(QString)

                              IIRC the implicit sharing of QString should minimise the impact of having a copy (the 3 GB of memory are not changed).

                              `They did not know it was impossible, so they did it.'
                              -- Mark Twain

                              V 1 Reply Last reply 16 Jun 2016, 13:01
                              2
                              • J JohanSolo
                                16 Jun 2016, 12:35

                                @VRonin said:

                                1. make sure setText signature is setText(const QString&) and not setText(QString)

                                IIRC the implicit sharing of QString should minimise the impact of having a copy (the 3 GB of memory are not changed).

                                V Offline
                                V Offline
                                VRonin
                                wrote on 16 Jun 2016, 13:01 last edited by
                                #15

                                @JohanSolo true but I don't know the content of setText, if you use setText(QString) and then use something as easy as append a new line at the end it triggers a huge copy that const QString& (or QString&) would prevent

                                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                ~Napoleon Bonaparte

                                On a crusade to banish setIndexWidget() from the holy land of Qt

                                1 Reply Last reply
                                2
                                • J JohanSolo
                                  16 Jun 2016, 12:25

                                  A QString loaded from a 1.5 GB text file needs about 3 GB of memory, as the characters are stored in UTF-16, see the doc. On 32-bits system this almost exceeds the max addressable memory... Depending on how you allocate the QString instance, the consumed memory is far above what is allowed for an application. I therefore think it's normal you have troubles doing this. I would find surprising if you could do this without problems.

                                  On a side note, I think you were told several times not to try to read such a huge file in one go...

                                  Q Offline
                                  Q Offline
                                  Qt Enthusiast
                                  wrote on 17 Jun 2016, 06:00 last edited by Qt Enthusiast
                                  #16

                                  @JohanSolo
                                  On a side note, I think you were told several times not to try to read such a huge file in one go...
                                  Hi all
                                  I have already made the change in my code after the discussion on forum as follows

                                  // BUFFER_SIZE is IMB
                                  if (FILE* fp = fopen(ofilename.toLatin1(), "r")) {
                                  QTextStream ts(fp, QIODevice::ReadOnly);
                                  while (!ts.atEnd()) {
                                  QString s = ts.read(BUFFER_SIZE);
                                  append(s);
                                  }
                                  }

                                  My problem of QString reading a file of 1.5 BG in one go is gone
                                  I am asking for such tool that detects memory errors so as to verify even after my change there are no memory errors . This is just to validate the my changes

                                  J 1 Reply Last reply 17 Jun 2016, 06:09
                                  0
                                  • Q Qt Enthusiast
                                    17 Jun 2016, 06:00

                                    @JohanSolo
                                    On a side note, I think you were told several times not to try to read such a huge file in one go...
                                    Hi all
                                    I have already made the change in my code after the discussion on forum as follows

                                    // BUFFER_SIZE is IMB
                                    if (FILE* fp = fopen(ofilename.toLatin1(), "r")) {
                                    QTextStream ts(fp, QIODevice::ReadOnly);
                                    while (!ts.atEnd()) {
                                    QString s = ts.read(BUFFER_SIZE);
                                    append(s);
                                    }
                                    }

                                    My problem of QString reading a file of 1.5 BG in one go is gone
                                    I am asking for such tool that detects memory errors so as to verify even after my change there are no memory errors . This is just to validate the my changes

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 17 Jun 2016, 06:09 last edited by
                                    #17

                                    @Qt-Enthusiast What do you mean by "memory errors"?
                                    Do you mean memory leaks? If so then you can use Valgrind as already suggested.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • Q Offline
                                      Q Offline
                                      Qt Enthusiast
                                      wrote on 17 Jun 2016, 06:15 last edited by
                                      #18

                                      I am try to run valigrind in my tool and will contact you in case of any errors

                                      1 Reply Last reply
                                      0
                                      • Q Offline
                                        Q Offline
                                        Qt Enthusiast
                                        wrote on 17 Jun 2016, 06:39 last edited by
                                        #19

                                        One more things even after this change , for 1.5 GB file if I move the scrollbar in one go to the end , the GUI hangs for some time . Any reason why this is so . I assume I will see the same behavior with setText

                                        1 Reply Last reply
                                        0
                                        • J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 17 Jun 2016, 06:57 last edited by
                                          #20

                                          I think the Qt editor component is not designed for such huge files, that's probably why it is slow. Who wants to write 1.5GB text files and how long will it take?

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          0

                                          1/20

                                          16 Jun 2016, 09:56

                                          • Login

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