PyQt5 .ui file not loading when run along with big process

i have a big project, but for simplicity reasons, i will show you the part of my application that end up in the “error”

So i have my MainScreen class that is responsible for opening the main screen of the application and handling a couple of other functionalities.

then inside my MainScreen class i have a method(function1) that opens a dialog by calling another class(OpenDialog).

class MainScreen(QtWidgets.QMainWindow):
    # do stuff

    def function1(self):
        dialog2 = OpenDialog(self, self.parameter)
        # do more stuff

Then i have my OpenDialog class which opens another screen and after it opens it, it must call some other function(test ) that does some calculation that take alot of time.

class OpenDialog(QtWidgets.QDialog):

    def __init__(self, parent, parameter):
        self.parameter = parameter
        uic.loadUi('interface/dialog.ui', self)


    def test(self):
        # do alot of stuff that take time

The problem is on the OpenDialog class, that if the test method is called on a button click(by removing the commenting line). First the dialog opens and then the calculations on the test are performed normally. But if i remove the button(because i dont want it) and i call the test method after the dialog loads, then the test methods is run and it performs all the calculations, but the dialog never opens.

Hi, I did have worked with PyQt 5 but I don’t know the exact answer you are looking for, but can give you a way. When I was working on PyQt, the major issue I faced is to constantly update values in the user interface which in one or other way will freeze the User Interface. Using Qthread concept can actually have a solution. I think you might have got a route to pave your path.

thats actually another problem i have.
Do you have any idea on how to put qthreads to this example?

Drop your Mail ID: I will drop my code.

or you can clone it here: GitHub - VishalBaskhi/UserInterface_PyQt5: This UI mainly deals with monitoring the robots motion, velocities, battery life, to start, kill, & save map in to a folder.

1 Like

can you please help me with using qthreads in the above example? How exactly can i call the test function on a qthread?

you basically emit the data according to the data type you need … For instance Qthread works like a pipeline …doing all the necessary stuff in other class and gives the particular output. once go to Qthread library page in PyQt5

Okay, im new to this things (QThreads and signals) so im probably doing something wrong.
so i set up the below code, where after the button in the dialog is pressed i need to run a function that takes alot of time, so i tried to set up a thread with a signal, but my function(bigTask) that runs all the stuff that take alot of time, is not run. Do you know how i can fix that?

class OpenDialog(QtWidgets.QDialog):

    def __init__(self, parent, parameter):
        self.parameter = parameter
        uic.loadUi('interface/dialog.ui', self)


    def init(self):
        self.worker = WorkerObject()
        self.worker_thread = QtCore.QThread()

class WorkerObject(QtCore.QObject):
    runTask = pyqtSignal()

    def bigTask(self):
          # does alot of stuff that take time

is class workerObject(QtCore.Qobject) is the class that u wanted to run ur function ??

1 Like

well ideally i would want to have this function inside the OpenDialog class, but in most examples that i saw they used a separate class.