QAudioDecoder - no service found - c++

I am trying to decode a .wav file using QAudioDecoder class. Even though I had included the QtMultimedia module into my .pro file by adding
QT += multimedia I am receiving an error that service for the QAudioDecoder was not found. I am not able to see where to problem lies.
I am using Qt 5.1.0 with MingGW 4.8 32 bit on Windows 7.
Error message:
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.audiodecode"
.pro file:
QT += core
QT += multimedia
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
main file:
#include <QCoreApplication>
#include <QAudioDecoder>
#include <QAudioBuffer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString pathToFile = "C:/Users/Mateusz/Documents/Szkola/Sound Processing/Lab1/artificial/easy/506Hz.wav";
QAudioDecoder decoder;
decoder.setSourceFilename(pathToFile);
decoder.start();
while(decoder.bufferAvailable()) {
QAudioBuffer buffer = decoder.read();
qDebug() << "Buffer size: " << buffer.byteCount();
}
return a.exec();
}

The Multimedia module uses plugins that are different on each platform (or compiler).
See http://qt-project.org/wiki/Qt_Multimedia_Backends
On Windows you have DirectShow and MediaFoundation (WMF).
Only the WMF plugin implements audio decoding features.
WMF plugin is only available with MSVC compiler.
See http://qt-project.org/doc/qt-5.1/qtmultimedia/platform-notes-windows.html

I had the same problem in Qt5.5 running under Linux.
The problem disappeared after upgrade to Qt5.5.1 using their MaintenanceTool.

I also struggled with this issue and finally got it to work by using the MS visual studio compiler in QT Creator, like Fernando Pelliccioni suggested.
Steps were:
-Use the Qt MaintenanceTool to add support for msvc2013
-Install Visual Studio 2013
-In Qt Creator go to Projects->Manage Kits and add msvc2013
-Build and run. Now QAudioDecoder works.

Related

Qt plugin not loaded

I have problems loading the built-in plugins for iconengines for a deployed application. Below is a minimal program to show the problem. It is not exactly the same, because Qt scans the plugin directories at start and registers it according to the file suffix, but I hope when I can get the minimal program to run, then the automatic scanning works, too.
main.cpp:
#include <QCoreApplication>
#include <QPluginLoader>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QPluginLoader loader("C:/Qt/5.15.1/msvc2019_64/plugins/iconengines/qsvgicon.dll");
if (loader.load()) {
qDebug() << "load ok";
} else {
qDebug() << "load failed";
}
return a.exec();
}
and PluginTest.pro:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += main.cpp
When I start it from the Qt Creator IDE, version 4.13.1, with Visual Studio 2019, 64 bit compiled, it prints "load ok". Now I do this from a "x64 Native Tools Command Prompt for VS 2019" command prompt in the project directory:
set PATH=%PATH%;C:\Qt\5.15.1\msvc2019_64\bin
mkdir deploy
copy release\PluginTest.exe deploy
windeployqt --release release\PluginTest.exe --plugindir deploy\QtPlugins
When I start PluginText.exe from the command prompt in the deploy directory, I get the output "load failed".
Additional information: when I set set qt_debug_plugins=1 and start the real application, I see these errors:
QFactoryLoader::QFactoryLoader() checking directory path "C:/projects/deploy/QtPlugins/iconengines" ...
QFactoryLoader::QFactoryLoader() looking at "C:/projects/deploy/QtPlugins/iconengines/qsvgicon.dll"
"Failed to extract plugin meta data from 'C:/projects/deploy/QtPlugins/iconengines/qsvgicon.dll'"
not a plugin
The qsvgicon.dll file is identical to "c:\Qt\5.15.1\msvc2019_64\plugins\iconengines\qsvgicon.dll".
I found the problem. It used some other Qt DLLs from the path when starting the application. This fixed it:
xcopy /y c:\Qt\5.15.1\msvc2019_64\bin\*.dll deploy

QT C++ application using QGIS API

I'm trying to develop a QT C++ application that uses QGIS API and I can't manage Qt Creator to compile the code. I've read several topicts at gis.stackexchange and from other sources. The information is mostly outdated and I havent't found a solution. What I need is an overall guideline about the compatibility of the following items that help me find the right combination:
Qt version: tried 4.8.6 and 5.9.
Qt compiler: tried MinGW, VS2008 Express (Qt 4.8.6) and VS Community 2017 (Qt 5.9)
QGIS version: tried 2.14 to 2.18.
QGIS compile: I only use the regular OSGeo4w installer and AFAIK QGIS is compiled with Qt4 and MSVC. I've tried to compile QGIS from source using MinGW with no success (again, versions compatibility issues).
Windows version: I'm using Windows 10 64bit.
OSGeo4W or OSGeo4W64.
Qt works Ok in every case with it's own libraries, but when I try to import QGIS libraries it gives an 'undefined reference' error when building, even though intellisense works fine as it recognizes QgsApplication as a member of qgsapplication.h.
The following is just a test I can't get working. My Pro file is:
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QgisWindow
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# QGIS
INCLUDEPATH += "C:/OSGeo4W64/apps/qgis-rel-dev/include"
INCLUDEPATH += "C:/OSGeo4W64/include"
LIBS += -L"C:/OSGeo4W64/apps/qgis-rel-dev/lib" -lqgis_core -lqgis_gui
DEFINES+=CORE_EXPORT=
DEFINES+=GUI_EXPORT=
# QGIS
main.cpp is:
#include <QApplication>
#include <qgsapplication.h>
int main(int argc, char *argv[])
{
QgsApplication app(argc, argv, true);
QgsApplication::setPrefixPath("C:/OSGeo4W64/apps/qgis-dev", true);
int retval = app.exec();
QgsApplication::exitQgis();
return retval;
}
Then it fails to build/compile whith this error:
main.cpp:20: error: undefined reference to `QgsApplication::QgsApplication(int&, char**, bool, QString const&, QString const&)'
I'm actually porting a PyQgis app I've made two years ago and as I'm fairly new to Qt Creator I'm stuck at he beginning.
I found the right combination of the above mentioned items to make it possible for Qt to import Qgis libraries and build the app:
Qt 4.8.6 for MSVC2010
Qt Creator 4.3.0 (from a Qt 5.9.0 installation). Qt Creator 3.0 may be used as well.
Visual C++ express 2010 - Include Windows Kits/SDK in install
OSGeo4W - Installed qgis-ltr-dev and all libraries
Cmake 2.8.2
To launch Qt Creator I use this .bat:
Creator.bat:
ECHO Setting up QGIS DEV ENV
set PYTHONPATH=
set OSGEO4W_ROOT=C:\OSGeo4W
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
#set QMAKESPEC=win32-msvc2010
#set PATH=%OSGEO4W_ROOT%\bin;%OSGEO4W_ROOT%\apps\qgis-ltr-dev\bin;%PATH%
#set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include;%OSGEO4W_ROOT%\apps\qgis-ltr-dev\include
#set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\apps\qgis-ltr-dev\lib
path %OSGEO4W_ROOT%\bin;%SYSTEMROOT%\System32;%SYSTEMROOT%;%SYSTEMROOT%\System32\wbem;C:\Program Files (x86)\Git\bin;C:\Tools\QtCreator\bin;%PATH%
set VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
start "Qt Creator" /B C:\Qt\Qt5.9.0\Tools\QtCreator\bin\qtcreator.exe %*
The PRO file:
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 1_hello_world_qgis_style
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
## QGIS
INCLUDEPATH += "C:/OSGeo4W/include"
INCLUDEPATH += "C:/OSGeo4W/apps/qgis-ltr-dev/include"
LIBS += -L"C:/OSGeo4W/apps/qgis-ltr-dev/lib" -lqgis_core -lqgis_gui
DEFINES+=CORE_EXPORT=
DEFINES+=GUI_EXPORT=
## QGIS
main.cpp file (adapted from Tim Sutton's examples)
// Qt Includes
#include <QApplication>
// QGIS Includes
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrendererv2.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>
int main(int argc, char ** argv)
{
// Start the Application
QgsApplication app(argc, argv, true);
app.setPrefixPath("D:/GIS");
QString myPluginsDir = "<path to Qgis plugins dir>";
QString myLayerPath1 = "<path to shapefile 1>";
QString myLayerBaseName1 = "Layer1";
QString myLayerPath2 = "<path to shapefile 2>";
QString myLayerBaseName2 = "Layer2";
QString myProviderName = "ogr";
// Instantiate Provider Registry
QgsProviderRegistry::instance(myPluginsDir);
// create maplayer instances
QgsVectorLayer * mypLayer1 = new QgsVectorLayer(myLayerPath1, myLayerBaseName1, myProviderName);
QgsVectorLayer * mypLayer2 = new QgsVectorLayer(myLayerPath2, myLayerBaseName2, myProviderName);
QgsSingleSymbolRendererV2 *mypRenderer1 = new QgsSingleSymbolRendererV2(QgsSymbolV2::defaultSymbol(mypLayer1->geometryType()));
QgsSingleSymbolRendererV2 *mypRenderer2 = new QgsSingleSymbolRendererV2(QgsSymbolV2::defaultSymbol(mypLayer2->geometryType()));
QList <QgsMapCanvasLayer> myLayerSet;
mypLayer1->setRendererV2(mypRenderer1);
mypLayer2->setRendererV2(mypRenderer2);
// Add Vector Layers to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer1, true);
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer2, true);
// Add Layers to the Layer Set
myLayerSet.append(QgsMapCanvasLayer(mypLayer1, true));
myLayerSet.append(QgsMapCanvasLayer(mypLayer2, true));
// Create the Map Canvas
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
mypMapCanvas->setExtent(QgsRectangle(-63.50, -28.10, -58.33, -24.00)); // Chaco
mypMapCanvas->setWheelAction(QgsMapCanvas::WheelAction(2) , 1.2);
mypMapCanvas->enableAntiAliasing(true);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
mypMapCanvas->freeze(false);
// Set the Map Canvas Layer Set
mypMapCanvas->setLayerSet(myLayerSet);
mypMapCanvas->setVisible(true);
mypMapCanvas->setWindowTitle("GIS DSH");
mypMapCanvas->refresh();
// Start the Application Event Loop
int retval = app.exec();
app.exitQgis();
return retval;
}
Paths are hardcoded (bad programming practice) but is just for this test.
And now it runs OK. Please, see my post on gis.stackexchange.com for the links and the screencaps of Qt Creator Build & Run configurations.

qt connect to oracle database on windows

On Windows 7 I installed qt creator and now I am trying to connect to the oracle database. I installed oracle client and plsql/developer and everything works fine. In qt creator I have error:
QsqlDatabase: QOCI driver not loaded
This qt documentation does not work for me. Is it clear tutorial how to do it on different platforms and situations?
Ok. I found solution.
Documentation says
set INCLUDE=%INCLUDE%;c:\oracle\oci\include
set LIB=%LIB%;c:\oracle\oci\lib\msvc
cd %QTDIR%\src\plugins\sqldrivers\oci
qmake oci.pro
nmake
If you are not using a Microsoft compiler, replace nmake with make in
the line above.
but make or nmake didn't work for me. Because I have not installed Microsoft Visual c++ on my machine.
I made instruction how to do this:
At first don't forget to install qt sources. During the installation check Sources checkbox.
then download and install oracle client win32_11gR2_client.zip. choose Runtime option during installation.(even if you are using 64 bit os download 32 bit version on oracle client). It creates c:\app\user\product\client_1... directory
then open qt minGW command line(start ->all peograms -> qt[version] -> [version] -> MinGW [version] -> Qt [version] for Desktop MinGW [version]) and move to the oci source folder:
cd C:\Qt\Qt[version]\[version]\Src\qtbase\src\plugins\sqldrivers\oci
then as documentation says include OCI(Oracle call interface) path and library:
set INCLUDE=%INCLUDE%;c:\app\user\product[version]\client_1\oci\include
set LIB=%LIB%;c:\app\user\product[version]\client_1\oci\lib\msvc
5.compile oci driver by executing these two lines:
qmake oci.pro
mingw32-make
it will creates two .dll files for you qsqloci.dll(release version) and qsqlocid.dll(debug version)
last step is to copy these two files into qtcreator installation folder.
go to the:
C:\Qt\Qt[version]\[version]\Src\qtbase\plugins\sqldrivers
and copy these files into:
C:\Qt\Qt[version]\[version]\mingw[version]\plugins\sqldrivers
and you are ready to go. to check connection try this code:
#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
db.setHostName("MY_IP_OR_HOST_NAME");
db.setDatabaseName("XE");
db.setUserName("test");
db.setPassword("test_password");
if (!db.open())
{
qDebug() << db.lastError().text();
}
else{
qDebug() << "Wow opened";
}
return a.exec();
}
You should use QODBC instea of QOCI.
gogagubi's answer is good, but step 4 does not work for me because set INCLUDE and LIB does not work for mingw32-make.
It need to set INCPATH and LIBS in oci.pro or use:
qmake "INCPAH +=c:\app\user\product[version]\client_1\oci\include
LIBS +=-Lc:\app\user\product[version]\client_1\oci\lib\msvc" oci.pro
Add the following lines to the oci.pro:
INCPATH +=c:\app\user\product[version]\client_1\oci\include
LIBS+=-Lc:\app\user\product[version]\client_1\oci\lib\msvc
ciao tutto;
you can connect to oracle db with QODBC driver if it exist;(default in Qt windows is exist) Like below:
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
db.setDatabaseName("Driver={Microsoft ODBC for Oracle};Server=127.0.0.1:1521;Uid=ep;Pwd=605605");
if(!db.open())
exit(0);
QSqlQuery query(db);
query.exec("select * from t");
while(query.next())
QMessageBox::information(0,"",query.value(1).toString());
this is connected and allow to execurte query;
buona fortuna;

QAudioDeviceInfo finds no default audio device on Ubuntu

I am trying to run the basic example from the QAudioDeviceInfo class reference, but Qt is not finding a default audio device.
Running this code shows no output:
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
qDebug() << "Device name: " << deviceInfo.deviceName();
I'm running Qt Creator 2.7.1 with Qt 5.0.2 on Ubuntu 13.10. Qt Multimedia was installed via apt-get. My pro file has QT += multimedia. My header file includes:
#include <QAudio>
#include <QAudioOutput>
#include <QAudioDeviceInfo>
Any ideas as to what I might be doing wrong?
It was fixed with a simple command:
sudo apt-get install libqt5multimedia5-plugins
Qt Multimedia requires this plugin package for audio backend support.
Had same issue in windows. Fixed it by replacing Qt5Multimedia.dll in \Python34\Lib\site-packages\PyQt* with one from \Qt\Tools\QtCreator\bin.
Spend some time finding solution so decided to leave it here.

Qt Creator + OpenCV: Program runs from .exe but not from editor

Well, I need to start working with OpenCV and as I'm used to working with QtCreator, I'm trying to make it all work together. I downloaded the latest OpenCV version, and compiled it with MinGW. Then, I created this little console project to try it out. Below is the .pro file:
QT += core
QT -= gui
TARGET = OpenCV_test4
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\\Librerias\\opencv2.3.1\\release\\include
LIBS += -LC:\\Librerias\\opencv2.3.1\\release\\lib \
-lopencv_core231.dll \
-lopencv_highgui231.dll \
-lopencv_imgproc231.dll \
-lopencv_features2d231.dll \
-lopencv_calib3d231.dll
Here is the main.cpp file:
#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// read an image
cv::Mat image= cv::imread("img.jpg");
// create image window named "My Image"
cv::namedWindow("OpenCV Window");
// show the image on window
cv::imshow("OpenCV Window", image);
// wait key for 5000 ms
cv::waitKey(5000);
return a.exec();
}
(I have tried this code with and without the QCoreApplication lines)
The deal is: It links and builds, and when runs from QtCreator only a terminal window called C:\QtSDK\QtCreator\bin\qtcreator_process_stub.exe appears with the line "Press RETURN to close this window..."
But, if I run the .exe from the project folder, it runs perfectly!! Why is QtCreator unable to launch the application? I found this really strange, and I would appreciate any hint about this. It's really not THAT important, but it is kind of a pain to have to run the .exe manually every time I change something to check how it works.
Thanks for your time :)
Additional Info:
I have tried both debug and release versions, the problem is the same in both of them.
Debugging does not work, it never stops at any breakpoint.
I'm running on Windows 7 Proffesional x64
SOLVED, I don't really know what I did, it suddenly worked and keeps working, I wish I could tell you how I fixed it but I have no idea, such a weird thing :(
Check Projects -> Run Settings -> Run in terminal. It have to be enabled, but seems to be disabled.
I have met same problem with QtCreator and OpenCL under Linux. Simple test program works after start from terminal and it does not work after start from the QtCreator.
I found the cause was hardcoded LD_LIBRARY_PATH in the project's run environment settings. I had dropped it to empty string and this had fixed issue.
I had the same issue with the following environment: Raspbian, Qt, openCV and a gui application.
old-ufo recommendation worked for me:
- First, enable "Run in terminal", which failed
- Then, disable "Run in terminal", which allowed me to correctly debug my app.
I understand that this is not scientific.