Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Problem of repeated reading
Forum Update on Monday, May 27th 2025

Problem of repeated reading

Scheduled Pinned Locked Moved C++ Gurus
14 Posts 3 Posters 3.9k Views
  • 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.
  • 9 Offline
    9 Offline
    9temps
    wrote on last edited by
    #1

    player->setMedia(QUrl::fromLocalFile(nomfichierwav));
    on
    c++
    windows

    keeps the button to play the sound, gives a windows error code 12

    How to fix it?

    kind regards

    P.S. The code works fine on Linux, the problem appears only on Windows

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

      Hi and welcome to devnet,

      With so little code there's only crystal ball debugging. Please show the complete method and how you call it

      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
      0
      • 9 Offline
        9 Offline
        9temps
        wrote on last edited by
        #3

        hello,
        Thank you for the answer.

        @
        QObject::connect (aa_bouton, SIGNAL (clicked()), qApp, SLOT (aasynthe ()));

        void clavier::aasynthe(char c, int n)
        {
        compte++;
        if (compte > 100000)
        {compte = 0;}
        snprintf(nomfichierwav, 32, "%c%d.wav", c, n);
        snprintf(lelecteur, 32, "lecteur%c%d%d", c, n, compte);

          QMediaPlayer *lelecteur;
          lelecteur = new QMediaPlayer;
          lelecteur->setMedia(QUrl::fromLocalFile(nomfichierwav));
          lelecteur->play();      
        

        }
        @

        At the beginning everything is working well, but after several calls I get the error

        I do not know if it's qt which limits the appeal to the player, or if it comes from my writing wav files.

        P.S.
        On linux Ubuntu :
        sudo apt-get install libqt5multimedia5-plugins

        @
        char nomfichierwav[32];
        char lelecteur[32];
        int compte = 0;

        void clavier::aasynthe(char c, int n)
        {
        compte++;
        if (compte > 100000)
        {compte = 0;}
        snprintf(nomfichierwav, 32, "%c%d.wav", c, n);
        snprintf(lelecteur, 32, "lecteur%c%d%d", c, n, compte);

          QMediaPlayer *lelecteur;
          lelecteur = new QMediaPlayer;
        

        // lelecteur->setMedia(QUrl::fromLocalFile(nomfichierwav));
        lelecteur->setMedia( QUrl::fromLocalFile(QFileInfo(nomfichierwav).absoluteFilePath()));
        lelecteur->play();
        }
        @

        [edit: Added missing coding tags @ SGaist]

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

          Something is wrong from the start: you can't connect a parameterless signal to a slot that has parameters

          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
          0
          • 9 Offline
            9 Offline
            9temps
            wrote on last edited by
            #5

            hello,
            Thank you for the answer, but sorry, I do not understand the answer.
            Does your answer shows how to solve my problem?
            Or, is your answer indicates that the line of code that I give is not working as it is?

            I gave the function that starts playing (void clavier::aasynthe), and indicated that it has a connect without further detail.

            To see the code under linux, this is :
            http://www.letime.net/vocale/lmfab1.tar.gz
            ( look at lmfab69 )
            and the explanation here
            http://doc.ubuntu-fr.org/lmfab

            I do not show the link under windows because the audio format is .jo fee owner under windows, only the code is given, and can only be used after purchasing the right to use the audio format abadie.jo

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

              No, it shows where there's one problem lying.

              In lmfab69, the button clicked signal is connected to the quit slot of QApplication. In your code you connect it to a slot that doesn't belong to QApplication and also that has a signature mismatch that makes the connection invalid.

              As for the error 12, "here's":http://technet.microsoft.com/en-us/library/cc732199(v=ws.10).aspx the relevant article from Microsoft

              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
              0
              • jeremy_kJ Offline
                jeremy_kJ Offline
                jeremy_k
                wrote on last edited by
                #7

                There's a QMediaPlayer object leaked by every call to clavier::aasynthe(char, int). Perhaps that's the cause of the error 12. According to the article SGaist linked to: Code 12: This device cannot find enough free resources that it can use.

                With regards to the connect(), see the "signals and slots documentation":http://qt-project.org/doc/qt-4.8/signalsandslots.html#signals-and-slots . In particular, The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)

                Asking a question about code? http://eel.is/iso-c++/testcase/

                1 Reply Last reply
                0
                • 9 Offline
                  9 Offline
                  9temps
                  wrote on last edited by
                  #8

                  hello,
                  Thank you for the clarification.
                  If I understand correctly, the click of mouse works as it should, but the call on the keyboard creates a defect that is only supported by Linux.
                  This fact comes from the keyboard is outside: QWidget ()

                  Do you think it is possible to put the keyboard in QWidget ()

                  kind regards

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

                    It's not a question of "only supported by Linux". Things are handled differently and by luck it's working, but anyway you still have a memory leak.

                    @
                    QMediaPlayer *lelecteur;
                    lelecteur = new QMediaPlayer;
                    @

                    You should only have one player and re-use it

                    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
                    0
                    • 9 Offline
                      9 Offline
                      9temps
                      wrote on last edited by
                      #10

                      hello,
                      Thank you for the clarification.

                      if I understand correctly, QMediaPlayer can not play multiple sounds simultaneously.

                      Although it appears no visible defect in the linux terminal.

                      must be changed

                      // void keyPressEvent(QKeyEvent* event);
                      in
                      void keyPressEvent(QKeyEvent *);

                      in clavier.h

                      Under Linux we can use fork and sox as a solution.
                      under windows can we use handle ?

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

                        No, it's not it's purpose. It should play one media at a time.

                        You would like to play several file at the same time ?

                        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
                        0
                        • 9 Offline
                          9 Offline
                          9temps
                          wrote on last edited by
                          #12

                          hello,
                          Yes, that's exactly it.
                          I need to play multiple sounds at the same time.
                          What I can do with fork and sox with Linux.
                          I wanted to do a version with QMediaPlayer

                          kind regards

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

                            QSoundEffect might be more suited

                            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
                            0
                            • 9 Offline
                              9 Offline
                              9temps
                              wrote on last edited by
                              #14

                              hello,
                              After several tests,
                              I think use sndfile.h
                              qt compiles fine, but the sounds are played on exit,
                              I have to correct the code.
                              kind regards

                              1 Reply Last reply
                              0

                              • Login

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