Log window


#1

Hi all,

What’s the easiest way to create a simple log window ? Using the TextEditor ?

TIA
/R


#2

good advice, don’t use TextEditor for logging if you plan on using that log in debug builds, it’s very slow when handling a lot of data, i use a CodeEditor component instead and it works very well.


#3

Seems a bit awkward :wink: I just might have me a listboxmodel which encapsulates the log.


#4

awkward how ? it’s really fast and works well, much faster then the normal texteditor


#5

In that you need a CodeDocument, and that inserting at the end of the document content seems cumbersome. Could you give a quick hint of how you’ve done it ?


#6

constructor of the window

CodeDocument statusCodeDocument;
CodeEditorComponent statusEditorComponent;

CtrlrStatus::CtrlrStatus() 
	:	Component (T("Status")), 
		statusEditorComponent(statusCodeDocument, 0),
		dumpCacheButton(T("Cache"))
{
}

when a message gets logged (i wrote my own Logger class, and my own LogMessage class to keep formatting, timestamps and so on)

void CtrlrStatus::messageLogged (CtrlrLog::CtrlrLogMessage *message)
{
	statusEditorComponent.insertTextAtCaret (message->format());
}

that’s it, not much really but it works nice.


#7

Thnx very much :slight_smile: I’ll try it out.


#8

Tried this

class EventListBox : public CodeEditorComponent
{
public:
    EventListBox() : CodeEditorComponent(m_doc, 0)
    {}

    void appendLogMessage(const String& logMessage)
    {
        insertTextAtCaret(logMessage);
    }

private:
    CodeDocument m_doc;

};

but it crashes on the first line of CodeEditorComponent constructor, looking like lines member is uninitialized… so there must be something more to it ? :?


#9

yeah i was having issues when subclassing the CodeEditorComponent class, that’s why i have a member in the class and am not doing inheritance, works for me.


#10

Is that becasue the CodeDocument member hasn’t been initialised before you pass it to the CodeEditorComponent constructor?


#11

With 100% certainty. I have no idea how to initialize it, and frankly I don’t have the time right now to figure it out. The docs said:

/** Creates a new, empty document. */ CodeDocument();
Well… the listbox approach works fine though.

Edit: Ah, I see now what you mean. Testing it out right now.

Edit2: It’s been a rough day… can’t believe I made this error :oops: But anyway, I can’t make it read-only and remove the caret so listbox it is…