Irrlicht log in QTextEdit

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Digan
Posts: 16
Joined: Tue Aug 24, 2010 11:21 am

Irrlicht log in QTextEdit

Post by Digan »

Hello

I wrote a Qt-widget based on this topic.

Render works fine.

Now I want to take the irrlicht - log through a QTextEdit - object.

I know how to display the log on messageBox through OnEvent in EventReceiver.

Code: Select all

bool EventReceiver::OnEvent(const irr::SEvent &event)
{
   switch(event.EventType) 
  {
   ...
   case EET_LOG_TEXT_EVENT:
   {
     const c8 *cs = event.LogEvent.Text;
     wchar_t *ws = new wchar_t[strlen(cs) + 1];
     int len = mbstowcs(ws,cs,strlen(cs));
     ws[len] = 0;
     Env->addMessageBox(L"Log", ws);
   }
    ...
  }
}
break;
But I want to display the log on QTextEdit.
How to listen EET_LOG_TEXT_EVENT event in own Qt - widget?

Best regard

Digan
Last edited by Digan on Mon Apr 04, 2011 2:10 pm, edited 1 time in total.
Image
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

First off, if you just wanna display the text to user, better use a QLabel insted of QTextEdit.

Second, unless I'm misunderstanding you, it seems to me you dont need to intercept anything. Why can't you just set the log text to QTextEdit with setText() ?


EDIT: ok, I guess what you're asking is how to GET the log text in the first place, not how to set it to a widget. I dont use Irrlicht logging, instead I have a QListWidget to which I manually add a QListWidgetItem every time I need to record/display something.

Since you have a Qt application and no Irrlicht event receiver, I guess you cant "listen" for Irrlicht events, insted you listen for some Qt event (just like mousePress, mouseRelease etc.) and then "pass" that event to Irrlicht. It means you generate an Irrlicht event based on some Qt event.
Last edited by xirtamatrix on Mon Apr 04, 2011 2:43 pm, edited 1 time in total.
to live, is natural; to die, is not!
Digan
Posts: 16
Joined: Tue Aug 24, 2010 11:21 am

Post by Digan »

xirtamatrix wrote:First off, if you just wanna display the text to user, better use a QLabel insted of QTextEdit.
No. This is needed for log in an editor.

Image

QTextEdit is well applied for this purpose.
Second, unless I'm misunderstanding you, it seems to me you dont need to intercept anything. Why can't you just set the log text to QTextEdit with setText() ?
Still for it needed a events of engine.
Own message will be, but I same way want text from engine - log.

For example. The events of mouse movement intercepted so:

Code: Select all

void QIrrlichtWidget::mouseMoveEvent(QMouseEvent* event)
{
   irr::SEvent irrEvent;

   irrEvent.EventType = irr::EET_MOUSE_INPUT_EVENT;

   if (device != 0)
   {
      irrEvent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;

      irrEvent.MouseInput.X = event->x();
      irrEvent.MouseInput.Y = event->y();
      irrEvent.MouseInput.Wheel = 0.0f; 


      device->postEventFromUser(irrEvent);
   }


   event->ignore();
}
But this event from the user.

EET_LOG_TEXT_EVENT - event from engine.

How to intercept the engine - event in a own Qt - widget?
It means you generate an Irrlicht event based on some Qt event.
Yes. See example above.
Last edited by Digan on Mon Apr 04, 2011 2:52 pm, edited 1 time in total.
Image
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

Digan wrote: For example. The events of mouse movement intercepted so:

Code: Select all

void QIrrlichtWidget::mouseMoveEvent(QMouseEvent* event)
{
   irr::SEvent irrEvent;

   irrEvent.EventType = irr::EET_MOUSE_INPUT_EVENT;

   if (device != 0)
   {
      irrEvent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;

      irrEvent.MouseInput.X = event->x();
      irrEvent.MouseInput.Y = event->y();
      irrEvent.MouseInput.Wheel = 0.0f; 


      device->postEventFromUser(irrEvent);
   }


   event->ignore();
}
But this event from the user.

EET_LOG_TEXT_EVENT - event from engine.

How to intercept the engine - event in a own Qt - widget?

Look carefully, you are NOT "listening" for an Irrlicht event, but for a Qt event and then when this Qt event triggers, you "generate" an Irrlicht event using device->postEventFromUser(irrEvent).
to live, is natural; to die, is not!
Digan
Posts: 16
Joined: Tue Aug 24, 2010 11:21 am

Post by Digan »

xirtamatrix wrote: Look carefully, you are NOT "listening" for an Irrlicht event, but for a Qt event and then when this Qt event triggers, you "generate" an Irrlicht event using device->postEventFromUser(irrEvent).
Yes. You are right.
This is an event from the user.

Can I get current event of engine without the Irrlicht event receiver?

Irrlicht event receiver and own Qt - widget in conflict... :?
Image
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

Digan wrote:
xirtamatrix wrote: Look carefully, you are NOT "listening" for an Irrlicht event, but for a Qt event and then when this Qt event triggers, you "generate" an Irrlicht event using device->postEventFromUser(irrEvent).
Yes. You are right.
This is an event from the user.

Can I get current event of engine without the Irrlicht event receiver?

Irrlicht event receiver and own Qt - widget in conflict... :?
I wouldn't say there is a conflict. Point is that you are running a QT application, so QT captures user interaction events. When you need to pass some event to Irrlicht, you always have to do it manually, like above.

I have never used Irrlicht logging, and dont know how it works, but try to figure out is there any QT event which you can listen for every time something is being written to log? If yes, generate an Irrlicht event from there.

Where is the code that writes to Irrlicht log? If you have access to it, one last option could be to emit a signal from there passing the most recently written text, then catch it in a slot which writes it to QTextEdit.
to live, is natural; to die, is not!
Digan
Posts: 16
Joined: Tue Aug 24, 2010 11:21 am

Post by Digan »

Thanks for reply.

I tried again to create a event receiver class.

Code: Select all

#pragma once

#include <irrlicht.h> 
#include <QTextEdit>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;

class MyEventReceiver :
	public IEventReceiver
{
public:
	MyEventReceiver(void);
	~MyEventReceiver(void);

	virtual bool OnEvent(const SEvent& event);
	void setLog(QTextEdit *logTextEdit);
private:
	QTextEdit *Log;

};

Code: Select all

#include "MyEventReceiver.h"

MyEventReceiver::MyEventReceiver(void)
{
}

MyEventReceiver::~MyEventReceiver(void)
{
}

bool MyEventReceiver::OnEvent(const SEvent& event)
{
	switch(event.EventType)
	{
		case EET_LOG_TEXT_EVENT:
		{
			const c8 *cs = event.LogEvent.Text;

			Log->insertPlainText(cs);
			Log->insertPlainText("\n");
		}
		break;

		default:
			break;
	}
	return 0;
}

void MyEventReceiver::setLog(QTextEdit *logTextEdit)
{
	Log = logTextEdit;
}
In a widget class I wrote:

Code: Select all

EventReceiver.setLog(Log);
device->setEventReceiver(&EventReceiver);
Everything fine works :)

Image
Image
Post Reply