PDA

View Full Version : Why does QCameraInfo/QCamera require an instance of QApplication?



FiddlerJoe
15th February 2016, 16:52
Hello,

I'd like to write a library that uses Qt's capabilites to control cameras. The lib is to be used in both console and gui applications. However, a QApplication object seems to be necessary for QCameraInfo to work properly. Why is this the case? Is it possible to use QCameraInfo and QCamera without a graphical user interace? Consider the following example. If no QApplication is constructed, QCameraInfo::availableCameras() always returns an empty list:



#include <iostream>
#include <QtMultimedia/QCamera>
#include <QtMultimedia/QCameraInfo>
#include <QApplication>

using namespace std;

int main(int argn, char** argv)
{
QApplication app(argn, argv);
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
cout << cameras.size() << endl;

return 0;
}


I'm using windows 10 and Qt 5.5.1. Thank you for your help!

d_stranz
15th February 2016, 22:08
You can try substituting QCoreApplication, which is the application class used in console apps. As for why an application is needed, it probably causes required shared libraries to be loaded, without which the availableCameras() call does not work.