'Threading a Qt6 splash screen

I am trying to thread a splash screen which is displayed in full screen after clicking a button in a GUI. Unfortunately it appears that the threading makes the application crash. Not sure what I am doing wrong, since the function itself without threading works fine. Also the threading is starting but the splash.show() functions seem to crash it. I am a bit clueless...

Basically i want to make the GUI accessable and not frozen while the BMP is displayed on the second screen.

Here is my method for the display of the BMP:

import sys
import time
import threading
import PyQt6.QtGui
from PyQt6.QtWidgets import QApplication, QSplashScreen
from PyQt6.QtGui import QPixmap
from PyQt6.QtCore import Qt

def Display():

    s = app.screens()[0]  # Get the right screen 0 or 1

    # Display info about secondary screen
    print('Screen Name: {} Size: {}x{} Available geometry {}x{} '.format(s.name(), s.size().width(), s.size().height(),
                                                                         s.availableGeometry().width(),
                                                                         s.availableGeometry().height()))

    # Select desired image to be displayed and set Resolutions
    PyQt6.QtCore.QSize(s.size().width(), s.size().height())
    pmpath = 'layer0000.bmp'
    print('Bitmap path: ' + pmpath)
    pixmap = QPixmap(pmpath)
    QPixmap()
    pixmap2 = pixmap.scaled(s.size().width(), s.size().height())
    print("Original Bitmap size: ", pixmap.size())  # show pixmap size
    print("Scaled to: ", pixmap2.size())  # show pixmap size

    # Splash screen approach
    splash = QSplashScreen(pixmap2)
    # Set the splash screen to desired image
    splash.show()  # Show the splash screen
    splash.windowHandle().setScreen(s)  # Set splash screen to secondary monitor
    splash.showFullScreen()  # Show the splash screen
    splash.setCursor(Qt.CursorShape.BlankCursor)  # Set Cursor Invisible on Splascreen
    time.sleep(3)
    splash.destroy()

    end_time = time.time()
    splash.destroy()
    print('Execution  time: ', end_time - start_time)


app = QApplication(sys.argv)
start_time = time.time()

#Threading the method
t1 = threading.Thread(target=Display)
t1.start()

# If i run this, it works properly. But in a thread it crashes ->
#Display()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source