PDA

View Full Version : QTextBrowser as logger



baray98
1st September 2007, 08:05
Hi,

I am using a Qtextbrowser to log/display messages from a device in my application. I used the append (QString &text) [slot] to add my messages to my logger. I noticed that that my app wont last 24 hours it will just crush I am suspecting that Qtextbrowser is just using up all memory my PC can afford.

I want to run my apps for months, how can i control Qtextbrowser from eating up all my memory? or What is the better solution to my objective, to show messages to my user that will run for months.

baray98

marcel
1st September 2007, 11:28
Are you sure it is the QTextBrowser? You might have memory leaks in other parts of your application. How much data does it gather in 24 hrs?

Anyway,if you want it to run for months, you should dump old data to disk since the log could grow to tens or hundreds of megabytes. You should display only a small part of the log. If the user scrolls the log then you have to load older/newer parts.

Or you could split the log in smaller files on disk. For example one log file for each week. You should let the user choose what log to see - i.e. choose the week and you just load the corresponding log file.

But you first must make sure there aren't any other problems.

Regards

baray98
1st September 2007, 19:16
259200 lines per day is the message average rate

I can even throw away the data every 1000 lines i just dont want it to crush.

I am 80% sure that it is the textbrowser that is doing it cause there is no other else active.

Now, my question is how can i limit the textBrowser to 1000 lines and then reset the browser?

baray98

darksaga
1st September 2007, 19:53
259200 lines per day is the message average rate

I can even throw away the data every 1000 lines i just dont want it to crush.

I am 80% sure that it is the textbrowser that is doing it cause there is no other else active.

Now, my question is how can i limit the textBrowser to 1000 lines and then reset the browser?

baray98

300000 logs * 100 (avg. loglength) * 2 bytes (QChar) ~= 57MB

qtextbrowser & qtextedit should be able to handle this, at least for one day, but it's absolutely insane to display & store your logs this way.

how about setting up a database of your choice, where you store your logs,
in your database you create a view, which shows the x newest logs.

to display the logs in your qt applicatin you then use a QTableview/QTreeview and a QSqlTableModel/QSqlRelationalTableModel populating it with data from the databaseview.