Irrlicht editor with QT

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
kingw
Posts: 2
Joined: Sat Jun 02, 2018 6:34 am

Irrlicht editor with QT

Post by kingw »

I want to write my own irrlicht scene editor with QT.

I create a class QIrrlichtWidget which derived from the QWidget, and reimplement the "paintEvent" mehtod to drive the Irrlicht drawing loop.

Code: Select all

 
 
//.h
 
class QIrrlichtWidget : public QWidget
{
signals:
    void updateIrrlicht(  );
 
public slots:
    void autoUpdateIrrlicht();
 
protected:
    virtual void paintEvent ( QPaintEvent * event );    
}
 
//.cpp
 
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) : QWidget(parent)
{
    connect( this, SIGNAL(updateIrrlicht()), this, SLOT(autoUpdateIrrlicht()) );
}
 
void QIrrlichtWidget::paintEvent(QPaintEvent *event)
{
    if ( m_device )
    {
        emit updateIrrlicht( m_device );
    }
}
 
void QIrrlichtWidget::autoUpdateIrrlicht()
{
    if(m_device->run())
    {
        m_device->getTimer()->tick();
        m_driver->beginScene(true, true, irr::video::SColor(255,125,0,0));
        m_scene->drawAll();
        m_guienv->drawAll();
        m_driver->endScene();
    }
}
 
but the QT throw the "QWidget::repaint: Recursive repaint detected" exception.

so, I use the Qt timer to avoid using the paintEvent.

Code: Select all

 
 
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) : QWidget(parent)
{
    connect( this, SIGNAL(updateIrrlicht()), this, SLOT(autoUpdateIrrlicht()) );
    
     startTimer(0);
}
 
void QIrrlichtWidget::timerEvent(QTimerEvent * event)
{
    if ( m_device )
    {
        emit updateIrrlicht( m_device );
    }
    event->accept();
}
 
 
Image

It is works well. But, there are still some problems. When I pass the QT mouse events to irrlicht engine, and operate the objects in irrlicht scene, the user experience is too bad. There are some delays that cannot be tolerated.

So, do anyone have any good ideas to solve the problem?
Lowe
Posts: 1
Joined: Mon May 20, 2019 8:28 pm

Re: Irrlicht editor with QT

Post by Lowe »

kingw wrote:I want to write my own irrlicht scene editor with QT.

I create a class QIrrlichtWidget which derived from the QWidget, and reimplement the "paintEvent" mehtod to drive the Irrlicht drawing loop.

Code: Select all

 
 
//.h
 
class QIrrlichtWidget : public QWidget
{
signals:
    void updateIrrlicht(  );
 
public slots:
    void autoUpdateIrrlicht();
 
protected:
    virtual void paintEvent ( QPaintEvent * event );    
}
 
//.cpp
 
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) : QWidget(parent)
{
    connect( this, SIGNAL(updateIrrlicht()), this, SLOT(autoUpdateIrrlicht()) );
}
 
void QIrrlichtWidget::paintEvent(QPaintEvent *event)
{
    if ( m_device )
    {
        emit updateIrrlicht( m_device );
    }
}
 
void QIrrlichtWidget::autoUpdateIrrlicht()
{
    if(m_device->run())
    {
        m_device->getTimer()->tick();
        m_driver->beginScene(true, true, irr::video::SColor(255,125,0,0));
        m_scene->drawAll();
        m_guienv->drawAll();
        m_driver->endScene();
    }
}
 
but the QT throw the "QWidget::repaint: Recursive repaint detected" exception.

so, I use the Qt timer to avoid using the paintEvent.

Code: Select all

 
 
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) : QWidget(parent)
{
    connect( this, SIGNAL(updateIrrlicht()), this, SLOT(autoUpdateIrrlicht()) );
    
     startTimer(0);
}
 
void QIrrlichtWidget::timerEvent(QTimerEvent * event)
{
    if ( m_device )
    {
        emit updateIrrlicht( m_device );
    }
    event->accept();
}
 
 
Image

It is works well. But, there are still some problems. When I pass the QT mouse events to irrlicht engine, and operate the objects in irrlicht scene, the user experience is too bad. There are some delays that cannot be tolerated.

So, do anyone have any good ideas to solve the problem?
I also have noticed the same issues that you have ever so wonderfully said. Hope those get fixed as I also feel the same way you do.

Regards,
Lowe
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Re: Irrlicht editor with QT

Post by Seven »

When using Microsoft MFC classes (similar to your try) I have to do something similar...I have not found a way around it.
chronologicaldot
Competition winner
Posts: 685
Joined: Mon Sep 10, 2012 8:51 am

Re: Irrlicht editor with QT

Post by chronologicaldot »

This is a problem more with the paintEvent() call of Qt being sporadic in timing. I'm inclined to think if it doesn't refresh fast enough, your entire frame will appear to pause in a jittery fashion.
The IrrlichtDevice::run() function "ticks" the clock and checks for inputs, so either call run() yourself or just call getTimer()->tick() but don't do both.
The files of interest are:
os.cpp
CIrrDeviceWin32.cpp
CIrrDeviceLinux.cpp
CIrrDeviceOSX.cpp

The last three of these contain the implementation of IrrlichtDevice::run() so you can see how it works.

I can't tell how you're constructing the IrrlichtDevice. Are you giving it the Qt window handle or having it run in it's own separate window? If it's in the Qt window, I presume you would be better off calling getTimer()->tick() and postEventFromUser() rather than calling run(), but you'll have to convert the Qt event manually to an Irrlicht SEvent.
Post Reply