Disable Direct3D for Qt6 and QML

Disable Direct3D for Qt6 and QML

With Qt6, your QML application display may not work on Windows. With Qt6, Direct3D graphics acceleration is used by default to display the GUI. On the other hand, it is possible that your video card is not working well. Also, this problem is often visible when the application is running in a VM (virtual machine, such as WMWare workstation).

When running, this type of problem results with the display of an empty window:

To disable hardware acceleration, modify the QSG_RHI_PREFER_SOFTWARE_RENDERER environment variable.

At the very beginning of the main (before QGuiApplication), add the following line:

qputenv("QSG_RHI_PREFER_SOFTWARE_RENDERER", QString("1").toUtf8());

For example:

int main(int argc, char *argv[])
{
    qputenv("QSG_RHI_PREFER_SOFTWARE_RENDERER", QString("1").toUtf8());    
    QGuiApplication app(argc, argv);
    ...
}

Graphics acceleration will then be disabled and the user interface will then be visible: