How to detect memory errors in Qt based gui
-
wrote on 16 Jun 2016, 09:56 last edited by A Former User
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
-
wrote on 16 Jun 2016, 10:06 last edited by
Sadly this is platform dependent, what OS are you on?
-
wrote on 16 Jun 2016, 10:22 last edited by
Red Hat Enterprise Linux Client release 5.8 (Tikanga)
-
wrote on 16 Jun 2016, 10:24 last edited by
Red Hat Enterprise Linux Client release 5.8 (Tikanga
I am also using C++ code to display the data in QTGUI
-
wrote on 16 Jun 2016, 10:44 last edited by
You can use valgrind then http://doc.qt.io/qtcreator/creator-valgrind-overview.html
-
wrote on 16 Jun 2016, 10:51 last edited by
I assume I need to have a debug library of QT in my code
-
I assume I need to have a debug library of QT in my code
@Qt-Enthusiast Why? Do you want to debug Qt code?
-
wrote on 16 Jun 2016, 12:05 last edited by
there is crash coming in code QString code . I am want verify after my fix if my fix is without any memory errors
-
wrote on 16 Jun 2016, 12:08 last edited by
I'm quite confident there are no memory leaks in QString code. what seems to be the problem?
-
wrote on 16 Jun 2016, 12:18 last edited by
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
-
wrote on 16 Jun 2016, 12:25 last edited by JohanSolo
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 theQString
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...
-
wrote on 16 Jun 2016, 12:29 last edited by VRonin
- I'd use QFile instead of fopen()
- make sure setText signature is
setText(const QString&)
and notsetText(QString)
- can you minimize the memory duplication replacing
setText(ts.readAll());
with something likewhile(!ts.atEnd()) append(ts.readLine());
-
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. -
- I'd use QFile instead of fopen()
- make sure setText signature is
setText(const QString&)
and notsetText(QString)
- can you minimize the memory duplication replacing
setText(ts.readAll());
with something likewhile(!ts.atEnd()) append(ts.readLine());
-
@VRonin said:
- make sure setText signature is
setText(const QString&)
and notsetText(QString)
IIRC the implicit sharing of QString should minimise the impact of having a copy (the 3 GB of memory are not changed).
wrote on 16 Jun 2016, 13:01 last edited by@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
- make sure setText signature is
-
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 theQString
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...
wrote on 17 Jun 2016, 06:00 last edited by Qt Enthusiast@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 -
@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@Qt-Enthusiast What do you mean by "memory errors"?
Do you mean memory leaks? If so then you can use Valgrind as already suggested. -
wrote on 17 Jun 2016, 06:15 last edited by
I am try to run valigrind in my tool and will contact you in case of any errors
-
wrote on 17 Jun 2016, 06:39 last edited by
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
-
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?
1/20