Page 1 of 1

Irrlicht editor with QT

Posted: Sun Feb 17, 2019 8:13 am
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?

Re: Irrlicht editor with QT

Posted: Mon May 20, 2019 8:31 pm
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

Re: Irrlicht editor with QT

Posted: Tue May 21, 2019 2:27 am
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.

Re: Irrlicht editor with QT

Posted: Wed Jun 19, 2019 7:54 pm
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.