Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is calling requestUpdate() in QEvent::UpdateRequest valid?



  • Hey there,
    I want to render with Vulkan to my Qt surface. From the examples and the existing code I've figured to call requestUpdate() inside of an UpdateRequest event callback, to enforce continuous rendering.

    Can someone tell me if this is the correct approach?

    (I want to subclass directly from QWindow and not use QVulkanWindow)


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What example are you talking about ?



  • Hello SGaist, thanks!

    Example is actually the wrong word, I looked into the source files of the QVulkanWindow class:
    https://code.woboq.org/qt5/qtbase/src/gui/vulkan/qvulkanwindow.cpp.html

    My primary goal is to render with Vulkan on a surface provided by Qt.
    I know that QVulkanWindow exists, but it already provides a SwapChain(etc.) which I prefer to create myself. So in the details description of QVulkanWindow it says:

    Note: QVulkanWindow does not always eliminate the need to implement a fully custom QWindow subclass as it will not necessarily be sufficient in advanced use cases.

    I want to make use of Qts platform independency while doing the Vulkan stuff myself. So I wonder if calling requestUpdate() out of a callback from QEvent::UpdateRequest is the right approach.

    bool event(QEvent* event) override
    {
        switch (event->type()) 
        {
        case QEvent::UpdateRequest:
            renderNow();
            return true;
        default:
            return QWindow::event(event);
        }
    }
    
    void renderNow()
    {
        // ... render code
        requestUpdate();
    }
    

    Thanks for bothering.



  • So after more research, I finally found the solution to what I was looking for myself:
    https://doc.qt.io/qt-5/qvulkaninstance.html#example

    I wonder how I could have missed that, during my hour long researches... probably because I didn't knew what exactly I was looking for.


Log in to reply