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
JavaScript
x
21
21
1
def main():
2
app = QApplication(sys.argv)
3
#window = QMainWindow()
4
# Convert darknet weights to tensorflow model
5
cmd1 = "python save_model.py --model yolov4"
6
# Run yolov4 deep sort object tracker on video
7
8
9
cmd2 = "python object_tracker.py --video ./data/video/project_video_2.mp4 --output
10
./outputs/output.avi --model yolov4 --dont_show --count"
11
12
TrackerProcess.sendParams(cmd1, cmd2, app)
13
window = TrackerProcess.main()
14
15
16
17
app.exec_()
18
19
if __name__ == '__main__':
20
main()
21
trackerProcess.py
JavaScript
1
23
23
1
def sendParams(cmd1, cmd2, a):
2
global command1, command2, app
3
command1 = cmd1
4
command2 = cmd2
5
app = a
6
7
def start_process_three(self):
8
#self.stop()
9
main_design.sendFile("./outputs/output.avi", app)
10
main_design.main()
11
12
def main():
13
#app = QApplication(sys.argv)
14
15
w = MainWindow()
16
w.show()
17
#app.exec()
18
return w
19
20
21
if __name__ == '__main__':
22
main()
23
main_design.py
JavaScript
1
26
26
1
def sendFile(passedFileName, a):
2
global fileName, app
3
fileName = passedFileName
4
app = a
5
6
7
def main():
8
#app = QtWidgets.QApplication(sys.argv)
9
#global app
10
Frame = QtWidgets.QFrame()
11
player = VideoPlayer()
12
player.resize(1024, 864)
13
ui = Ui_Frame()
14
ui.setupUi(Frame, player)
15
player.show()
16
Frame.show()
17
player.playVideoFile(fileName, app)
18
app.exec_()
19
20
#return player
21
22
23
24
if __name__ == "__main__":
25
main()
26
VideoPlayer.py
JavaScript
1
19
19
1
def playVideoFile(self, fileName, a):
2
#fileName, _ = QFileDialog.getOpenFileName(self, "Open Movie",
3
#QDir.homePath())
4
global app
5
app = a
6
if fileName != '':
7
self.mediaPlayer.setMedia(
8
QMediaContent(QUrl.fromLocalFile(fileName)))
9
if self.mediaPlayer.state() == QMediaPlayer.PlayingState:
10
self.mediaPlayer.pause()
11
else:
12
self.mediaPlayer.play()
13
def main():
14
app.exec_()
15
return app
16
17
if __name__ == "__main__":
18
main()
19
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!