Page 3 of 4
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Fri Oct 21, 2011 10:22 am
by serengeor
YankzzDev wrote:serengeor wrote:YankzzDev wrote:hmmm, i have another question...
after i load the model, it's displayed on the screen, but i load another model, it's displayed 2 model with selected one and previous one...
how i can clear the previous one?
Read the F***** API and get some c++ skills
Not trying to be rude, but basically it seams that we're programming for you.
the rude one is you... i not asking you to programming for me.....
Because i don't understand so i ask..
i am not expert like you(C++ Expert maybe than C++ god)..
i am newbie in c++ and irrlicht engine too...
my basic languange is vb.net..
if i don't understand, so i ask? it's fault?
It's bad to ask someone for doing something for you without putting any effort into it yourself. If you want to code irrlicht apps/games you will have to learn c++ or use a wrapper for .NET, theres no excuse as
"my basic languange is vb.net.." so I need you guys to do this for me!
i am not expert like you(C++ Expert maybe than C++ god)..
I'm far from expert myself and I might have asked these questions myself, but now I see that doing research on your own makes life easier most of the time.
Just try to study and understand how c++ works, than reading api will be easy enough

Re: Irrlicht / Qt4 integration + QtCreator
Posted: Tue Jan 10, 2012 11:43 pm
by rookie
I am trying to embed kinect with qt & irrlicht. I am able to display irrlicht in 1 window & my kinect stream in other window. When I merge them nothing shows up on top of the kinect stream. I am trying to recreate something like this.
http://www.youtube.com/watch?v=1jbvnk1T4vQ
I am doing all the model rendering A& physics using irrlicht & want hem to display stuff over the body displayed in kinect stream. Right now I am able to display my shirt model in a different window using irrlicht but can't merge them. I used the following to merge them but nothing shows up
Params.WindowId = (void *)winID;
winID is winId() returned from the QMainWindow. My model is derived from Qgraphicsitem. I can' use QWidget since I can't display the widget over the video stream. The widget overwrites the kinect video stream that is the video stream is not displayed if I use QWidget & hence I am using QGraphicsItem. Please help me. Also how to setup the irrlicht camera so that it shows the stream correctly??
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Wed Jan 11, 2012 12:12 am
by aanderse
i'm not entirely sure about the issue, but i can tell you that using the id of the main window isn't what you want
in qt the main window has a "centralWidget" which is the widget you want to grab the id from
you can set the central widget to any widget you like via setCentralWidget
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Wed Jan 11, 2012 8:54 pm
by rookie
Thanks for your help. I tried using this->centralwidget() but that returns 0. I tried setCntralWidget(widget) to the widget which has all qgraphicsviews but no change. I tried adding IrrlichtDevice to the setcentralwidget but obviously doesn't accept irrlichtdeivce parameters. Since I am doing all my irrlicht stuff inside qgraphicsitem would that cause any problems??
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Thu Jan 12, 2012 3:19 am
by aanderse
well...
i haven't tested, but you might try something like this:
QWidget *irrlichtWidget = new QWidget ();
irrlichtWidget->setAttribute (Qt::WA_OpaquePaintEvent, true);
irrlichtWidget->setAttribute (Qt::WA_PaintOnScreen, true);
QGraphicsProxyWidget *proxyWidget = yourGraphicsScene->addWidget (irrlichtWidget);
now proxyWidget is your graphics item
i'd be interested to hear if that works or not
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Thu Jan 12, 2012 7:18 pm
by rookie
I have already created a class derived from QGraphicsItem that is Model. I am doing all irrlicht rendering inside Models paint function. So when I create a Models instance & add it to QGraphicsScene it should draw the irrlicht rendering since I have merged the window where kinect stream is being displayed with he irrlicht window. Also I have already added the following lines in my MainWindows constructor
QGLWidget *widget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
widget->makeCurrent();
view->setViewport(widget);
view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
Also the documentation says QGLWidget & QgraphicsProxyWidget shouldn't be merged. I tried using Qwidget irrlichwidget instead of QGLWidget without QgraphicsProxyWidget & it still remains the same. Where should I use proxyWidget because when I don't use it it says
QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent
& it automatically shuts down the program without displaying any kinect video stream. It doesn't give me this error when I am adding many other Qlabel to the scene.
Also I just found out that the irrlicht window is being displayed behind the window which displays the kinect video. Any idea how to solve that.
Thank a lot for all your help.
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Thu Jan 12, 2012 11:47 pm
by rookie
@aanderse I got the setCentralWidget working but the model still doesn't show up.
Can anyone help me with the following??
http://irrlicht.sourceforge.net/forum/v ... =1&t=45611
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Fri Jan 13, 2012 4:02 am
by aanderse
after looking at your new thread i want to mention that on the first page of this thread there is a QIrrlichtWidget class which should help you out
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Fri Jan 13, 2012 7:31 pm
by rookie
I know but I don't want it to be QWidget...Anyways thanks for your help
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Tue Jul 03, 2012 12:53 pm
by ritti
Hi, first of all thx for this nice tutorial.
I have a Problem with actions that were done during the game runs.
I started with the Irrlichts tutorial 07.Collision and built on it so now i can select and send units around with the mouse.
The Problem is that all this is in a while loop:
Code: Select all
while(mainWindow.getIrrlichtWidget()->getIrrlichtDevice()->run())
if (mainWindow.getIrrlichtWidget()->getIrrlichtDevice()->isWindowActive())
{... //code to send units around and watch for collisions
If i do so i wont never get to
So the window never opens
All works fine if i remove the loop but i cant send units around.
How do I have to do it so that the window opens and the QWidget updates on changes?
I hope u know what I mean

Thx Ritti
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Wed Jul 04, 2012 9:01 am
by Virion
hi ritti. check out the first post again. you will see the implementation of timerEvent():
Code: Select all
void QIrrlichtWidget::timerEvent(QTimerEvent* event)
{
// Emit the render signal each time the timer goes off
if (device != 0)
{
emit updateIrrlichtQuery(device);
}
event->accept();
}
basically it will run emit updateIrrlichtQuery(device); on every frame, which, works just like while(mainWindow.getIrrlichtWidget()->getIrrlichtDevice()->run())
therefore, you should put your "send units around" and "watch for collisions" code within the updateIrrlichtQuery() function, since it's called on every frame. Hope this help.
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Sun Jul 15, 2012 8:00 pm
by ritti
Ah jeah cool thx for your answer it works great now

Re: Irrlicht / Qt4 integration + QtCreator
Posted: Sat Nov 16, 2013 11:35 pm
by fdgonzalez
It is perfect. Thanks so much. It is really what I wanted.
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Tue Jan 06, 2015 5:32 pm
by AGameDev
Hello,
I've done some small updates to this code. I'm posting this update here, because I think that there could be a better/ more modern approach for integrating Irrlicht into Qt. But first I have to try my idea.
That's why I post the slightly modernized version here. It works with Qt 5.x and was freed from some now unnecessary code or updated where it was necessary.
If my idea works, I will publish a new posting.
Have fun!
Code: Select all
// ui_mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 800, 25));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QObject::tr("Main Window"));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // MAINWINDOW_H
Code: Select all
// mainapplicationwindow.h
#ifndef MAINAPPLICATIONWINDOW_H
#define MAINAPPLICATIONWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include "ui_mainwindow.h"
#include "qirrlichtwidget.h"
// Include the namespace from ui_MainWindow.h
namespace Ui {
class MainWindow;
}
// Class that contains the main window as well as the irrlicht widget
class MainApplicationWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainApplicationWindow(QWidget *parent = 0);
~MainApplicationWindow();
QIrrlichtWidget* getIrrlichtWidget(){return &irrWidget;}
private:
Ui::MainWindow *ui;
QIrrlichtWidget irrWidget;
protected:
virtual void resizeEvent(QResizeEvent* event);
};
#endif // MAINAPPLICATIONWINDOW_H
Code: Select all
// qirrlichtwidget.h
#ifndef QIRRLICHTWIDGET_H
#define QIRRLICHTWIDGET_H
#include <QMainWindow>
#include <QWidget>
#include <QResizeEvent>
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
// Our Irrlicht rendering widget
class QIrrlichtWidget : public QWidget
{
Q_OBJECT
public:
explicit QIrrlichtWidget(QWidget *parent = 0);
~QIrrlichtWidget();
// Returns a pointer to the Irrlicht Device
IrrlichtDevice* getIrrlichtDevice();
// Create the Irrlicht device and connect the signals and slots
void init();
signals:
// Signal that its time to update the frame
void updateIrrlichtQuery(IrrlichtDevice* device);
public slots:
// Function called in response to updateIrrlichtQuery. Renders the scene in the widget
void updateIrrlicht(IrrlichtDevice* device);
protected:
virtual void paintEvent(QPaintEvent* event);
virtual void timerEvent(QTimerEvent* event);
virtual void resizeEvent(QResizeEvent* event);
IrrlichtDevice *device;
// We keep the camera inside this widget so we can resize the window dynamically
ICameraSceneNode* camera;
};
#endif // QIRRWIDGET_H
Code: Select all
// main.cpp
#include "mainapplicationwindow.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MainApplicationWindow mainWindow;
mainWindow.show();
mainWindow.getIrrlichtWidget()->init();
// Make sure the Irrlicht Device exists before trying to use it
if(mainWindow.getIrrlichtWidget()->getIrrlichtDevice())
{
ISceneManager *smgr = mainWindow.getIrrlichtWidget()->getIrrlichtDevice()->getSceneManager();
IVideoDriver *driver = mainWindow.getIrrlichtWidget()->getIrrlichtDevice()->getVideoDriver();
// Just display a simple mesh
IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2");
if (!mesh)
{
mainWindow.getIrrlichtWidget()->getIrrlichtDevice()->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("media/sydney.bmp") );
}
}
return app.exec();
}
Code: Select all
// mainapplicationwindow.cpp
#include "mainapplicationwindow.h"
MainApplicationWindow::MainApplicationWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Setup for the Irrlicht Widget
irrWidget.setParent(ui->centralWidget);
irrWidget.setGeometry(0, 0, size().width(), size().height());
}
MainApplicationWindow::~MainApplicationWindow()
{
delete ui;
}
void MainApplicationWindow::resizeEvent(QResizeEvent *event)
{
irrWidget.setGeometry(0, 0, size().width(), size().height());
event->accept();
}
Code: Select all
// qirrlichtwidget.cpp
#include "qirrlichtwidget.h"
#include "mainapplicationwindow.h"
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) :
QWidget(parent)
{
device = 0;
}
QIrrlichtWidget::~QIrrlichtWidget()
{
if(device != 0)
{
device->closeDevice();
device->drop();
}
}
// Create the Irrlicht device and connect the signals and slots
void QIrrlichtWidget::init()
{
// Make sure we can't create the device twice
if(device != 0)
return;
// Set all the device creation parameters
SIrrlichtCreationParameters params;
params.AntiAlias = 0;
params.Bits = 32;
params.DeviceType = EIDT_X11;
params.Doublebuffer = true;
params.DriverType = EDT_OPENGL;
params.EventReceiver = 0;
params.Fullscreen = false;
params.HighPrecisionFPU = false;
params.IgnoreInput = false;
params.LoggingLevel = ELL_INFORMATION;
params.Stencilbuffer = true;
params.Stereobuffer = false;
params.Vsync = false;
// Specify which window/widget to render to
params.WindowId = reinterpret_cast<void*>(winId());
params.WindowSize.Width = width();
params.WindowSize.Height = height();
params.WithAlphaChannel = false;
params.ZBufferBits = 16;
// Create the Irrlicht Device with the previously specified parameters
device = createDeviceEx(params);
if(device)
{
// Create a camera so we can view the scene
camera = device->getSceneManager()->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
}
// Connect the update signal (updateIrrlichtQuery) to the update slot (updateIrrlicht)
connect (this, &QIrrlichtWidget::updateIrrlichtQuery, this, &QIrrlichtWidget::updateIrrlicht);
// Start a timer. A timer with setting 0 will update as often as possible.
startTimer(0);
}
IrrlichtDevice* QIrrlichtWidget::getIrrlichtDevice()
{
return device;
}
void QIrrlichtWidget::paintEvent(QPaintEvent* event)
{
if(device != 0)
{
emit updateIrrlichtQuery(device);
}
event->accept();
}
void QIrrlichtWidget::timerEvent(QTimerEvent* event)
{
// Emit the render signal each time the timer goes off
if (device != 0)
{
emit updateIrrlichtQuery(device);
}
event->accept();
}
void QIrrlichtWidget::resizeEvent(QResizeEvent* event)
{
if(device != 0)
{
dimension2d<u32> widgetSize;
widgetSize.Width = event->size().width();
widgetSize.Height = event->size().height();
device->getVideoDriver()->OnResize(widgetSize);
ICameraSceneNode *cam = device->getSceneManager()->getActiveCamera();
if (cam != 0)
{
cam->setAspectRatio((f32)widgetSize.Width / (f32)widgetSize.Height);
}
}
}
void QIrrlichtWidget::updateIrrlicht( irr::IrrlichtDevice* device )
{
if(device != 0)
{
device->getTimer()->tick();
SColor color (255,100,100,140);
device->getVideoDriver()->beginScene(true, true, color);
device->getSceneManager()->drawAll();
device->getVideoDriver()->endScene();
}
}
Re: Irrlicht / Qt4 integration + QtCreator
Posted: Thu Jan 15, 2015 8:29 am
by rustyk
This is really nice AGameDev. Thanks for sharing and now with QT5. Awesome work!
I'm new to irrlicht but have done some small QTApps. Do you mind posting a downloadable template for a complete reference?
Thanks again.