Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QMediaPlayer makes crash the app
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer makes crash the app

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 2 Posters 843 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tony13
    wrote on last edited by Tony13
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • SGaistS SGaist

        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.

        T Offline
        T Offline
        Tony13
        wrote on last edited by
        #3

        @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 instance

        an 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.

        SGaistS T 2 Replies Last reply
        0
        • T Tony13

          @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 instance

          an 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.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply
          1
          • T Tony13

            @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 instance

            an 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.

            T Offline
            T Offline
            Tony13
            wrote on last edited by
            #5

            @Tony13 Ok, Thank you, I'm working on it.

            1 Reply Last reply
            0
            • SGaistS SGaist

              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.

              T Offline
              T Offline
              Tony13
              wrote on last edited by Tony13
              #6

              @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

              SGaistS 1 Reply Last reply
              0
              • T Tony13

                @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

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Tony13 why are you creating player in the body of the main function ? It should be a member of your MainWindow class.

                What happens there is that the application crashes because player is unknown to MainWindow.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved