Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. OpenAL-Soft does not allow to stop Qt5 application

OpenAL-Soft does not allow to stop Qt5 application

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
5 Posts 2 Posters 594 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.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on last edited by
    #1

    Hi,

    I cannot stop the application:

    Widget.h

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QtWidgets/QWidget>
    #include <AL/alc.h>
    #include <AL/al.h>
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = nullptr);
        ~Widget();
    
    private:
        ALCdevice *m_pALCDevice;
        ALCcontext *m_pALCContext;
    };
    #endif // WIDGET_H
    

    Widget.cpp

    #include "Widget.h"
    #include <iostream>
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
        const char *devicename = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
        m_pALCDevice = alcOpenDevice(devicename);
        std::cerr << alGetError() << std::endl;
        if (!m_pALCDevice)
        {
            std::cerr << "Failed to get sound device" << std::endl;
            return;
        }
    }
    
    Widget::~Widget()
    {
        if (!alcMakeContextCurrent(nullptr))
        {
            std::cerr << "Failed to set context to nullptr" << std::endl;
        }
    
        if (!alcCloseDevice(m_pALCDevice))
        {
            std::cerr << "Failed to close sound device" << std::endl;
        }
    }
    

    main.cpp

    #include "Widget.h"
    
    #include <QtWidgets/QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
        return a.exec();
    }
    

    .pro

    QT       += core gui
    
    INCLUDEPATH += "E:\Libs\openal-soft-1.22.0-bin\include"
    LIBS += -L"E:\Libs\openal-soft-1.22.0-bin\libs\Win32"
    LIBS += -lOpenAL32.dll
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++11
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        main.cpp \
        Widget.cpp
    
    HEADERS += \
        Widget.h
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    RESOURCES += \
        Sounds.qrc
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What happens to your application ?

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

      8Observer88 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What happens to your application ?

        8Observer88 Offline
        8Observer88 Offline
        8Observer8
        wrote on last edited by
        #3

        @SGaist said in OpenAL-Soft does not allow to stop Qt5 application:

        What happens to your application ?

        AL_INVALID_OPERATION.gif

        I added the closeEvent() and openAlErrorToString() methods:

        Widget.cpp

        #include "Widget.h"
        #include <iostream>
        
        Widget::Widget(QWidget *parent)
            : QWidget(parent)
        {
        //    const char *devicename = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
            m_pALCDevice = alcOpenDevice(nullptr);
            std::cerr << openAlErrorToString(alGetError()) << std::endl;
            if (!m_pALCDevice)
            {
                std::cerr << "Failed to get sound device" << std::endl;
                return;
            }
        }
        
        Widget::~Widget()
        {
        
        }
        
        void Widget::closeEvent(QCloseEvent *event)
        {
            if (!alcMakeContextCurrent(nullptr))
            {
                std::cerr << "Failed to set context to nullptr" << std::endl;
            }
        
            if (!alcCloseDevice(m_pALCDevice))
            {
                std::cerr << "Failed to close sound device" << std::endl;
            }
        }
        
        std::string Widget::openAlErrorToString(int err)
        {
            switch (err)
            {
              case AL_NO_ERROR: return "AL_NO_ERROR";
              case AL_INVALID_OPERATION: return "AL_INVALID_OPERATION";
              case AL_INVALID_NAME: return "AL_INVALID_NAME";
              case AL_INVALID_ENUM: return "AL_INVALID_ENUM";
              case AL_INVALID_VALUE: return "AL_INVALID_VALUE";
              case AL_OUT_OF_MEMORY: return "AL_OUT_OF_MEMORY";
              /* ... */
              default:
                return "Unknown error code";
            }
        }
        

        Widget.h

        #ifndef WIDGET_H
        #define WIDGET_H
        
        #include <QtWidgets/QWidget>
        #include <AL/alc.h>
        #include <AL/al.h>
        
        class Widget : public QWidget
        {
            Q_OBJECT
        
        public:
            Widget(QWidget *parent = nullptr);
            ~Widget();
        
        private:
            void closeEvent(QCloseEvent *event) override;
            std::string openAlErrorToString(int err);
        
            ALCdevice *m_pALCDevice;
            ALCcontext *m_pALCContext;
        };
        #endif // WIDGET_H
        
        1 Reply Last reply
        0
        • 8Observer88 Offline
          8Observer88 Offline
          8Observer8
          wrote on last edited by
          #4

          I have another example where I play a sound but that example has the same problem with closing the application.

          1 Reply Last reply
          0
          • 8Observer88 Offline
            8Observer88 Offline
            8Observer8
            wrote on last edited by
            #5

            I found another library that works fine:

            Widget.h

            #ifndef WIDGET_H
            #define WIDGET_H
            
            #include <QtWidgets/QWidget>
            #include <fmod.h>
            
            class Widget : public QWidget
            {
                Q_OBJECT
            
            public:
                Widget(QWidget *parent = nullptr);
                ~Widget();
            
            private:
                FMOD_SYSTEM *m_pSystem;
                FMOD_SOUND *m_pSound;
            };
            #endif // WIDGET_H
            

            Widget.cpp

            #include "Widget.h"
            #include <QtCore/QFile>
            #include <QtCore/QDebug>
            
            // https://forum.qt.io/topic/49342/solved-fmod-does-not-play-a-sound-from-qresource/2
            
            Widget::Widget(QWidget *parent)
                : QWidget(parent)
            {
                FMOD_System_Create(&m_pSystem, FMOD_VERSION);
                FMOD_System_Init(m_pSystem, 32, FMOD_INIT_NORMAL, 0);
            
            //    FMOD_System_CreateSound(m_pSystem, "Assets/spell.ogg", FMOD_DEFAULT, 0, &m_pSound);
            
                QString soundPath(":/Assets/spell.ogg");
                QFile f(soundPath);
                if (!f.open(QIODevice::ReadOnly))
                {
                    qDebug() << "Faild to open the file: " << soundPath;
                    return;
                }
                QByteArray soundData = f.readAll();
            
                FMOD_CREATESOUNDEXINFO* exinfo = new FMOD_CREATESOUNDEXINFO();
                exinfo->length = static_cast<unsigned int>(soundData.length());
                exinfo->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
                FMOD_System_CreateSound(m_pSystem, soundData.data(), FMOD_OPENMEMORY, exinfo, &m_pSound);
            
                FMOD_Sound_SetMode(m_pSound, FMOD_LOOP_OFF);
            
                FMOD_System_PlaySound(m_pSystem, m_pSound, 0, false, 0);
            }
            
            Widget::~Widget()
            {
            }
            

            main.cpp

            #include "Widget.h"
            
            #include <QApplication>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                Widget w;
                w.show();
                return a.exec();
            }
            

            .pro

            QT       += core gui
            
            INCLUDEPATH += "C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
            LIBS += -L"C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86"
            LIBS += -lfmod
            
            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
            
            CONFIG += c++11
            
            # You can make your code fail to compile if it uses deprecated APIs.
            # In order to do so, uncomment the following line.
            #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
            
            SOURCES += \
                main.cpp \
                Widget.cpp
            
            HEADERS += \
                Widget.h
            
            # Default rules for deployment.
            qnx: target.path = /tmp/$${TARGET}/bin
            else: unix:!android: target.path = /opt/$${TARGET}/bin
            !isEmpty(target.path): INSTALLS += target
            
            RESOURCES += \
                Assets.qrc
            
            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