Unsolved VkSurfaceKHR surfaceForWindow(QWindow *window)
-
Looking through the source code it fails at
QWindowsNativeInterface::nativeResourceForWindow: 'vkSurface' requested for null window or window without handle.
void *QWindowsNativeInterface::nativeResourceForWindow(const QByteArray &resource, QWindow *window) { if (!window || !window->handle()) { qWarning("%s: '%s' requested for null window or window without handle.", __FUNCTION__, resource.constData()); return nullptr; } auto *bw = static_cast<QWindowsWindow *>(window->handle()); int type = resourceType(resource); if (type == HandleType) return bw->handle(); switch (window->surfaceType()) { case QWindow::RasterSurface: case QWindow::RasterGLSurface: if (type == GetDCType) return bw->getDC(); if (type == ReleaseDCType) { bw->releaseDC(); return nullptr; } break; case QWindow::VulkanSurface: #if QT_CONFIG(vulkan) if (type == VkSurface) return bw->surface(nullptr, nullptr); // returns the address of the VkSurfaceKHR, not the value, as expected #endif break; default: break; } qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData()); return nullptr; }
What is required for a QWindow to be properly initialized to have these values?
-
Hi,
You might want to share the code you are actually using so it will help spot what is going on.
-
class Test_Window : Public QWindow{ Test_Window(){ setSurfaceType(VulkanSurface); m_instance=std::make_shared<QVulkanInstance>(); } void init(*vulkan_object object){ //Throws error here object->surface = surfaceForWindow(this); m_instance->setVkInstance(object->instance); m_instance->create(); setVulkanInstance(&*m_instance); } private: std::shared_ptr<QVulkanInstance> m_instance; }; int main(int argc, char** argv){ QGuiApplication app(argc,argv) vulkan_object obj{}; Test_Window test_window{}; test_window.init(vulkan_object); test_window.show(); app.exec(); }
-
It seems the QWindow::handle() is NULL, how to fix this?
-
Do you mean winId ?
In any case, shouldn't you use QVulkanWindow ?
-
The solution is to execute
window->show()
before you try and create a surface.Also QVulkanWindow manages a bunch of vulkan types which is... not what you want.