Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Show Camera inside of a Widget-App
Qt 6.11 is out! See what's new in the release blog

Show Camera inside of a Widget-App

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 3 Posters 1.3k Views 2 Watching
  • 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.
  • P Offline
    P Offline
    peter-70
    wrote on last edited by
    #1

    I have a QMainWindow Class where a function is called:

    void MyTest::OnOpenCamera()
    {
        this->setVisible(false);
        auto cameraApp = new CameraApp;
        cameraApp->Show(this);
    }
    

    In class CameraApp the following code is implemented:

    CameraApp::CameraApp()
    {
        QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
        QZXing::registerQMLTypes();
        NativeHelpers::registerApplicationInstance(this);
    
        this->LoadQml();
    }
    
    CameraApp::~CameraApp()
    {
    }
    
    void CameraApp::LoadQml()
    {
        this->engine.load(QUrl(QStringLiteral("qrc:/qml/camera.qml")));
    }
    
    void CameraApp::Show(QWidget* parent)
    {
        QObject* topLevel = this->engine.rootObjects().value(0);
        QQuickWindow* window = qobject_cast<QQuickWindow*>(topLevel);
        window->show();
    }
    

    Now the camera window is showing indeed, but it's not transparent.

    What can I do, to see a normally camera screen inside of my app?
    Thank you!

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Might be a silly question but why not use QCameraViewfinder ?

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        peter-70
        wrote on last edited by
        #3

        The example is an QZXingLive-example. There is no QCameraViewfinder in use.

        Just in main.cpp

        int main(int argc, char *argv[])
        {
            QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
            QGuiApplication app(argc, argv);
        
            QZXing::registerQMLTypes();
        
            Application customApp;
            customApp.checkPermissions();
        
            return app.exec();
        }
        

        and then in application.cpp

        Application::Application()
        {
            //both signals will be connected to the same function for
            //simplicity
        
            connect(this, &Application::onPermissionsGranted,
                    this, &Application::initializeQML);
        
            connect(this, &Application::onPermissionsDenied,
                    this, &Application::initializeQML);
        
            NativeHelpers::registerApplicationInstance(this);
        }
        
        void Application::initializeQML()
        {
            engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        }
        
        void Application::checkPermissions()
        {
        #if defined(Q_OS_ANDROID)
            //intentionally called in the C++ thread since it is blocking and will continue after the check
            qDebug() << "About to request permissions";
        
                QAndroidJniObject::callStaticMethod<void>("org/ftylitak/qzxing/Utilities",
                                                "requestQZXingPermissions",
                                                "(Landroid/app/Activity;)V",
                                                QtAndroid::androidActivity().object());
            qDebug() << "Permissions granted";
        #else
            emit onPermissionsGranted();
        #endif //Q_OS_ANDROID
        }
        

        Now I wonder, how can I implement this as a library implementation for my app.

        1 Reply Last reply
        0
        • P peter-70

          I have a QMainWindow Class where a function is called:

          void MyTest::OnOpenCamera()
          {
              this->setVisible(false);
              auto cameraApp = new CameraApp;
              cameraApp->Show(this);
          }
          

          In class CameraApp the following code is implemented:

          CameraApp::CameraApp()
          {
              QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
              QZXing::registerQMLTypes();
              NativeHelpers::registerApplicationInstance(this);
          
              this->LoadQml();
          }
          
          CameraApp::~CameraApp()
          {
          }
          
          void CameraApp::LoadQml()
          {
              this->engine.load(QUrl(QStringLiteral("qrc:/qml/camera.qml")));
          }
          
          void CameraApp::Show(QWidget* parent)
          {
              QObject* topLevel = this->engine.rootObjects().value(0);
              QQuickWindow* window = qobject_cast<QQuickWindow*>(topLevel);
              window->show();
          }
          

          Now the camera window is showing indeed, but it's not transparent.

          What can I do, to see a normally camera screen inside of my app?
          Thank you!

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @peter-70 said in Show Camera inside of a Widget-App:

          Now the camera window is showing indeed, but it's not transparent.

          What is not transparent?
          It looks like you want to use a barcode scanner, right?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            peter-70
            wrote on last edited by peter-70
            #5

            Yes, exactly!

            When I try to run the code in my app, the qml content is visible, but it has a white background. So I can't see the camera input signal/image

            jsulmJ 1 Reply Last reply
            0
            • P peter-70

              Yes, exactly!

              When I try to run the code in my app, the qml content is visible, but it has a white background. So I can't see the camera input signal/image

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @peter-70 Does checkPermissions() succeed?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                peter-70
                wrote on last edited by
                #7

                Yes! The engine.load is called. The qml file can be found. The content of the qml file is drawn, but the background of it, is white and not transparent.

                But this is only when I try to run the app, as a lib, from my widget app. If the scanner app runs as standalone app, everything is ok.

                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