Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. VkSurfaceKHR surfaceForWindow(QWindow *window)
Qt 6.11 is out! See what's new in the release blog

VkSurfaceKHR surfaceForWindow(QWindow *window)

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scott_craig
    wrote on last edited by scott_craig
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You might want to share the code you are actually using so it will help spot what is going on.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        scott_craig
        wrote on last edited by scott_craig
        #3
        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();
        }
        1 Reply Last reply
        0
        • S Offline
          S Offline
          scott_craig
          wrote on last edited by
          #4

          It seems the QWindow::handle() is NULL, how to fix this?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Do you mean winId ?

            In any case, shouldn't you use QVulkanWindow ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              scott_craig
              wrote on last edited by scott_craig
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved