Unsolved How to detect memory errors in Qt based gui
-
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
-
Sadly this is platform dependent, what OS are you on?
-
Red Hat Enterprise Linux Client release 5.8 (Tikanga)
-
Red Hat Enterprise Linux Client release 5.8 (Tikanga
I am also using C++ code to display the data in QTGUI
-
You can use valgrind then http://doc.qt.io/qtcreator/creator-valgrind-overview.html
-
I assume I need to have a debug library of QT in my code
-
@Qt-Enthusiast Why? Do you want to debug Qt code?
-
there is crash coming in code QString code . I am want verify after my fix if my fix is without any memory errors
-
I'm quite confident there are no memory leaks in QString code. what seems to be the problem?
-
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
-
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...
-
- 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. -
@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).
- make sure setText signature is
-
@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
-
@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. -
I am try to run valigrind in my tool and will contact you in case of any errors
-
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?