Results 1 to 2 of 2

Thread: Why does QCameraInfo/QCamera require an instance of QApplication?

  1. #1

    Default Why does QCameraInfo/QCamera require an instance of QApplication?

    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:

    Qt Code:
    1. #include <iostream>
    2. #include <QtMultimedia/QCamera>
    3. #include <QtMultimedia/QCameraInfo>
    4. #include <QApplication>
    5.  
    6. using namespace std;
    7.  
    8. int main(int argn, char** argv)
    9. {
    10. QApplication app(argn, argv);
    11. QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    12. cout << cameras.size() << endl;
    13.  
    14. return 0;
    15. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Why does QCameraInfo/QCamera require an instance of QApplication?

    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.

Similar Threads

  1. Replies: 2
    Last Post: 1st August 2011, 07:30
  2. Getting QApplication instance from the executable
    By nikhilqt in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2009, 11:16
  3. QApplication focus from other friend instance
    By patrik08 in forum Qt Programming
    Replies: 0
    Last Post: 9th June 2008, 13:42
  4. Share QApplication instance (exe and dll)
    By cquinones in forum Qt Programming
    Replies: 11
    Last Post: 18th October 2007, 19:10
  5. QApplication instance
    By nile.one in forum Qt Programming
    Replies: 9
    Last Post: 5th October 2007, 13:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.