QMediaPlayer makes crash the app
-
Hi, for a personal project, I'm developping an desktop app.
The objective is to play sounds when I click on the big pads called 'cartouche'.
I've an issue and can't figure what is causing this.
To recreate the issue :- drag and drop sound file to one pad
-drag and drop sound file to an other(or the same while playing)
-click the pad (or press play)
-click the second pad (or the same while playing)
-the app crashes
But if after the first click on one pad, you click stop button, there is no problem to use pads after this.
If someone has an idea to solve this, I link you my project on github :
https://github.com/Bowsen13/qtdesigner - drag and drop sound file to one pad
-
Hi and welcome to devnet,
Your architecture is pretty strange. You seem to try to implement some sort of singleton that knows way too much about the classes that should use it.
I would recommend refactoring that. There's no need for that singleton. You can have one single playback manager connected to your two buttons that handles the file change.
-
@SGaist Hi, thank you for your answer.
I'm not a confirmed programmer at all, do you mean, I should create one class to set the pushbuttons' actions (play, pause, mute ...), an other to read and output audio ?
I did one singleton becuase from my button class (une_cartouche) I couldn't get the instance of an other class.
In realality I can, but I'm using Qt designer that generates a file, but to use drag and drop for push buttons, I need to reimplement the class. Which is unconvinient, because I need to change the generated class of Qt designer to make this drag and drop work and if I want to pass an instance of a class (a playback reader as you recommended) I need to modify again and again this generated file. So it is becomming unefficient for me to use qt designer.
The singleton helped me to bypass the fact that I need to instantiate my buttons by passing an other class instance in params.
If you know how to implement drag and drop without modifiyng the mainwindow file, I'll take it.Otherwise, should I implement separatly the drag and drop function, and the clicked function ?
One : class PushButton(QPushButton): #handeling drag and drop function, stores the file in this instancean other : class PushButtonClick(): #handle the click of the pushbuttons, set file from one's instance to the playback manager.
It looks like for me, kind of losing 'oriented object' programming, because of splitting the pushbutton's functionalities. -
There's no need to make that many classes for your pads.
You have to decouple things in your design. Your pads should not be concerned by what happens when they are clicked on as much as your player don't need to know what was used to call play on it.
-
@SGaist Hello, even when I put everithing in the same file it's not working, to execute the bug :
Reimplement QpushButton to set up drag and drop,
store dropped file into this class.
From main class, set up on clicked actions :
player.setSource(self.pad.file)
player.play()Even with the same pad or an other the bug occurs.
Steps :
1- drag and drop to set file on pad
2- click the pad to set QMediaPlayer's source and play
3- while playing drag an other file to the pad
4- click the pad -> Appplication freezes
If you do the same steps with the same file it's working.
If you do the same steps with the same file, it's working, and after doing this, you can do it with an other file and it's working. Why the first time when we put a different file it's not working ?Git link : https://github.com/Bowsen13/Qt-last.git