Problem of repeated reading



  • 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


  • Lifetime Qt Champion

    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



  • 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]


  • Lifetime Qt Champion

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



  • 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


  • Lifetime Qt Champion

    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



  • 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.)



  • 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


  • Lifetime Qt Champion

    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



  • 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 ?


  • Lifetime Qt Champion

    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 ?



  • 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


  • Lifetime Qt Champion

    QSoundEffect might be more suited



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.