Integration with Qt

Started by
3 comments, last by SiS-Shadowman 13 years, 5 months ago
Hello all,
I would like to integrate my framework with Qt
for example I want to achive something like this:

void QWidget::paintEvent(QPaintEvent* e){myFramework->render()}

where method render look like:
while(true){update();draw();}


but I dont have a clue, how can I do this :(

I will be grateful for any hint.

Best Regards
kszewczyk
Advertisement
Qt has it's own main loop, and from what I understand it is very hard or not possible to bypass that. However, you can use a QTimer with interval set to 0 so it triggers every frame. Inside the timer event function you call your update function and after that the repaint() function of the widget. The repaint function will trigger the paintEvent function immediately, from which you can then repaint the window.
You should explain what your framework does and why you want to do this. We need more context in order to help you.
I want to be able to paint on QWidget with my framework,my gole is to do something similar to Ogre Engine:

QPaintEngine* paintEngine() const { return NULL; }void GLWidget::paintEvent(QPaintEvent *e){    ogreRoot->_fireFrameStarted();        ogreRenderWindow->update();    ogreRoot->_fireFrameEnded();    e->accept();}


basically for now I have render module, core module and resources module, the core module is responsible to connect all of modules and provide framework API to user.
When creating your framework's graphics device you need to pass the widget's platform handle to it. This is done so that the device can actually render to the right window. You obtain it the handle by calling the following function: QWidget::winID.

The second thing is to update the logic at a certain frequency, probably 30hz. This can be done by using a timer that runs every 33ms. This timer also causes the widget to paint itself (by calling update) so that the framework can paint to the window (painting outside paintEvent is never a good idea).

I usually create a widget for that purpose:
class CustomWidget : public QWidget{    Q_OBJECT    QTimer   m_timer;    YourFramework*   m_framework;    CustomWidget(QWidget* parent)        : QWidget(parent)    {        QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateFramework()));        m_timer.start(33);        m_framework = new YourFrame(winId());    }    virtual ~CustomWidget()    {        delete m_framework.    }private slots:    void updateFramework()    {        m_framework->update();        update(); //< Posts a QPaintEvent in the main loop    }protected:    virtual void paintEvent(QPaintEvent* event)    {        m_framework->render();        event->accept();    }};


Usually you need to handle a QResizeEvent as well, to resize frame buffers and the like.

This topic is closed to new replies.

Advertisement