Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved QCoreApplication: "CoInitialize has not been called" on QAudioDeviceInfo::availableDevices. QApplication is OK.

    General and Desktop
    3
    3
    224
    Loading More Posts
    • 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.
    • C
      cdwijs last edited by

      Hi All,

      I'm writing a console application that will plays wav files. When I use QApplication everything works as expected, when I use QCoreApplication, I get this error: when I call QAudioDeviceInfo::availableDevices.

      onecore\com\combase\objact\objact.cxx(836)\combase.dll!76F4E86C: (caller: 76F4D83B) ReturnHr(1) tid(3a70) 800401F0 CoInitialize has not been called.
      

      Is there, besides increased memory usage, a downside of using QApplication instead of QCoreApplication for console application?
      Is there another way to fix this error?
      Why does QAudioDeviceInfo::availableDevices() need the qt gui framework to be loaded?

      I've made a minimal program that shows the error:

      //#include "mainwindow.h"
      
      #include <QApplication>
      #include <QDebug>
      #include <QAudioDeviceInfo>
      QAudioDeviceInfo m_deviceInfo;
      
      int main(int argc, char *argv[])
      {
          //QApplication a(argc, argv); //no warnings
          QCoreApplication a(argc, argv); /*generates these warnings:
      onecore\com\combase\objact\objact.cxx(836)\combase.dll!76F4E86C: (caller: 76F4D83B) ReturnHr(1) tid(3a70) 800401F0 CoInitialize has not been called.
      onecore\com\combase\objact\objact.cxx(836)\combase.dll!76F4E86C: (caller: 76F4D83B) ReturnHr(2) tid(3a70) 800401F0 CoInitialize has not been called.
      onecore\com\combase\objact\objact.cxx(836)\combase.dll!76F4E86C: (caller: 76F4D83B) ReturnHr(3) tid(3a70) 800401F0 CoInitialize has not been called.
      onecore\com\combase\objact\objact.cxx(836)\combase.dll!76F4E86C: (caller: 76F4D83B) ReturnHr(4) tid(3a70) 800401F0 CoInitialize has not been called.*/
          int idx = 1;
          const QAudio::Mode mode = idx == 0 ? QAudio::AudioInput : QAudio::AudioOutput;
          for (auto &deviceInfo: QAudioDeviceInfo::availableDevices(mode))
          {
              qDebug()<<deviceInfo.deviceName();
          } /*debug output in both cases:
      "Speakers (High Definition Audio Device)"
      "1 - CF791 (AMD High Definition Audio Device)"
      "Digital Audio (S/PDIF) (High Definition Audio Device)"
      "Speakers/Headphones (Realtek(R) Audio)"*/
          //MainWindow w;
          //w.show();
          return a.exec();
      }
      

      My versions:

      Qt Creator 4.12.0
      Based on Qt 5.14.2 (MSVC 2017, 32 bit)
      Built on Apr 22 2020 01:29:13
      From revision 10fece1795
      
      Windows 10 Enterprise version 1903 OS build 18362.1016
      

      My compile output:

      Starting: "C:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -j12
      C:/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Debug
      mingw32-make[1]: Entering directory '[..]/New folder/build-untitled5-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
      g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled5 -I. -IC:\Qt\5.14.2\mingw73_32\include -IC:\Qt\5.14.2\mingw73_32\include\QtMultimedia -IC:\Qt\5.14.2\mingw73_32\include\QtWidgets -IC:\Qt\5.14.2\mingw73_32\include\QtGui -IC:\Qt\5.14.2\mingw73_32\include\QtANGLE -IC:\Qt\5.14.2\mingw73_32\include\QtNetwork -IC:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IC:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\main.o ..\untitled5\main.cpp
      g++ -Wl,-subsystem,windows -mthreads -o debug\untitled5.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o  C:\Qt\5.14.2\mingw73_32\lib\libQt5Multimedia.a C:\Qt\5.14.2\mingw73_32\lib\libQt5Widgets.a C:\Qt\5.14.2\mingw73_32\lib\libQt5Gui.a C:\Qt\5.14.2\mingw73_32\lib\libQt5Network.a C:\Qt\5.14.2\mingw73_32\lib\libQt5Core.a  -lmingw32 C:\Qt\5.14.2\mingw73_32\lib\libqtmain.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.7.25-win32\lib -LC:\Utils\postgresql\pgsql\lib -lshell32 
      mingw32-make[1]: Leaving directory '[..]/New folder/build-untitled5-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
      
      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        I would guess that QtMultimedia at least needs a QGuiApplication

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 0
        • B
          Bonnie last edited by Bonnie

          It's quite usual to have some COM warnings in debug mode.
          I would ignore those if there're no other problems.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post