Skip to content
Advertisement

Solution for : QCoreApplication::exec: The event loop is already running [closed]

So, I am a complete beginner in Python. This is my first ever application in this. I have these several files of Python classes. Using PyQT5 to make a desktop GUI object tracking app. When I am calling them from one another this error shows up.

QCoreApplication::exec: The event loop is already running

main.py

def main():
 app = QApplication(sys.argv)
 #window = QMainWindow()
 # Convert darknet weights to tensorflow model
 cmd1 = "python save_model.py --model yolov4" 
 # Run yolov4 deep sort object tracker on video


 cmd2 = "python object_tracker.py --video ./data/video/project_video_2.mp4 --output 
 ./outputs/output.avi --model yolov4 --dont_show --count"

 TrackerProcess.sendParams(cmd1, cmd2, app)
 window = TrackerProcess.main()



 app.exec_()
    
if __name__ == '__main__':
main()

trackerProcess.py

def sendParams(cmd1, cmd2, a):
 global command1, command2, app
 command1 = cmd1
 command2 = cmd2
 app = a

def start_process_three(self):
 #self.stop()        
 main_design.sendFile("./outputs/output.avi", app)
 main_design.main()

def main():
 #app = QApplication(sys.argv)

 w = MainWindow()
 w.show()
 #app.exec()
 return w
 

if __name__ == '__main__':
    main()

main_design.py

def sendFile(passedFileName, a):
 global fileName, app
 fileName = passedFileName
 app = a


def main():
 #app = QtWidgets.QApplication(sys.argv)
 #global app
 Frame = QtWidgets.QFrame()
 player = VideoPlayer()
 player.resize(1024, 864)
 ui = Ui_Frame()
 ui.setupUi(Frame, player)
 player.show()
 Frame.show()
 player.playVideoFile(fileName, app)
 app.exec_()

#return player

    

if __name__ == "__main__":
    main()

VideoPlayer.py

 def playVideoFile(self, fileName, a):
   #fileName, _ = QFileDialog.getOpenFileName(self, "Open Movie",
            #QDir.homePath())
    global app
    app = a
    if fileName != '':
        self.mediaPlayer.setMedia(
                QMediaContent(QUrl.fromLocalFile(fileName))) 
    if self.mediaPlayer.state() == QMediaPlayer.PlayingState:
        self.mediaPlayer.pause()
    else:
        self.mediaPlayer.play()
def main():
 app.exec_()
 return app

if __name__ == "__main__":
        main()

Please someone give a proper solution. I am tired of searching for a loophole in the code. Any advice is invited. Thank you.

Advertisement

Answer

Okay, so I refactored my code and made them appear in fewer files. Tried to call app.exec_() in one main file only. Finally the error is gone!

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement