Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Display the QML screen on Ui :: MainWindow



  • Hi everybody!

    I'm new bie, I use QLM to display the camera, and I want this display frame to be bring to front on ui.form in Ui :: MainWindow
    but at present when
    win.show ();
    the QML screen will be hidden (cannot see the camera screen)

    int main(int argc, char *argv[])
    {
      QApplication a(argc, argv);
      MainWindow win;
    
      Window* window = new Window();
      PropertyList* propertyList = window->getPropertyList();
    
      QQmlApplicationEngine engine;
      engine.rootContext()->setContextProperty(QStringLiteral("propertyList"), propertyList);
      engine.load(QUrl(QStringLiteral("qrc:/motlan.qml")));
      if (engine.rootObjects().isEmpty())
      {
          return -1;
      }
    
      win.show();
      return a.exec();
    }
    

    Thanks!


  • Qt Champions 2017

    You're mixing two technologies, but is it really what you want to do?
    If you just want the QML, then just drop the widget stuff altogether (as in the QML examples). If you indeed want to mix the two there's the QQuickWidget wrapper.



  • @kshegunov said in Display the QML screen on Ui :: MainWindow:

    ou're mixing two technologies, but is it really what you want to do?
    If you just want the QML, then just drop the widget stuff altogether (as in the QML examples). If you indeed want to mix the two there's the QQuickWidget wrapper.

    Thanks !
    In qml I receive video from camera, then pass it to C ++ to display on the label, but the received data is blank.
    .qml

    Camera
        {
            id: camera
            objectName: "set_camera"
    
            imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
    
            exposure
            {
                exposureCompensation: -1.0
                exposureMode: Camera.ExposurePortrait
            }
    
            focus
            {
                focusMode: Camera.FocusContinuous
                focusPointMode: Camera.FocusPointCenter
            }
    
            flash.mode: Camera.FlashRedEyeReduction  // giảm hiệu ứng mắt đỏ flash
    
            imageCapture
            {
                onImageCaptured:
                {
                    photoPreview.source = preview  // Show the preview in an Image
                }
            }
    
        }
    
        VideoOutput
        {
            orientation: 270  // xoay khung camera
            source: camera
            anchors.fill: parent
            focus : false // to receive focus and capture key events when visible
        }
    

    .cpp

        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/motlan.qml")));
    
        QObject *qmlCamera = engine.rootObjects().at(0)->findChild<QObject*>("set_camera");
        ui->inform->setText(qmlCamera->objectName());  // I test show is fine !
        QCamera *camera1 = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));   
    
        probe_.setSource(camera1);
        connect(&probe_,SIGNAL(videoFrameProbed(const QVideoFrame &)),
                        this, SLOT(present(const QVideoFrame &)));
    

    Now, I do not receive SIGNAL of probe, the received data is not a QVideoFrame ?

    Regards !


  • Lifetime Qt Champion

    Hi,

    What OS are you on ?



  • @SGaist said in Display the QML screen on Ui :: MainWindow:

    What OS are you on ?

    I use android 11, Qt5.15, NDK21, JDK1.8
    Hope you just help me out, I am in desperate need of my project !


  • Lifetime Qt Champion

    Why are you trying to get the output from a QML video output when there's already a QML item to do exactly that ?



  • @SGaist said in Display the QML screen on Ui :: MainWindow:

    Why are you trying to get the output from a QML video output when there's already a QML item to do exactly that ?

    Because I am using opencv for android on c ++, but for c ++, I can't get real time video of camera (I tried different ways but to no avail)
    Error displaying video from the camera, Please help me in this section
    https://forum.qt.io/topic/126213/error-displaying-video-from-the-camera/10

    Many thanks!


  • Lifetime Qt Champion

    What do you want to do with OpenCV ?

    Depending on that it does not make sens to grab the images from Qt to process them with OpenCV, just use OpenCV directly for that and Qt only at the end.



  • @SGaist said in Display the QML screen on Ui :: MainWindow:

    What do you want to do with OpenCV ?
    Depending on that it does not make sens to grab the images from Qt to process them with OpenCV, just use OpenCV directly for that and Qt only at the end

    Thanks !
    I simply need to get the video camera as Mat, to process the image information, but in Qt C ++ Mainwindow, it doesn't seem to support to get the image directly from the camera.
    For example I use this case for Android 11, Qt5.15, arm64-v8a

         for (const QCameraInfo &cameraInfo : cameras) {
             if (cameraInfo.deviceName() == "back")
             {
                 qDebug() <<"video start";
                 camera = new QCamera(cameraInfo);
                 viewfinder = new QCameraViewfinder();
                 viewfinder->showMaximized();
                 camera->setCaptureMode(QCamera::CaptureViewfinder);
                 camera->setViewfinder(viewfinder);
                 viewfinder->show();
                 camera->start();
                 qDebug() <<"video finish";
             }
         }
    

    and get an error message

    W libuntitled_arm64-v8a.so: The video surface is not compatible with any format
    

    I spent a lot of time dealing with this but still to no avail
    Regards !


  • Lifetime Qt Champion

    As I already wrote: use OpenCV directly to get the data from the camera.



  • @SGaist said in Display the QML screen on Ui :: MainWindow:

    As I already wrote: use OpenCV directly to get the data from the camera.

    As I tried the Qt Android does not support OpenCv open directly from the camera, for example the following function always returns false

    capture.open(0);                      // mở camera 0
    
        if(!capture.isOpened())
        {
            qDebug() << "Could not open camera" << 0;
            return;
        }
    

    There are many places on the forum that also talk about this
    https://forum.qt.io/topic/41961/accessing-the-android-camera-in-qt/16
    and
    https://github.com/opencv/opencv/issues/11952

    Thanks!


  • Lifetime Qt Champion

    Which version of OpenCV are you using ?

    This merge request implemented the Androïd support.



  • @SGaist said in Display the QML screen on Ui :: MainWindow:

    Which version of OpenCV are you using ?
    This merge request implemented the Androïd support.

    I use Qt5.15, OpenCV4.5.2, I hope you can show me how to use it
    with this Opencv + Qt, I am still using its features normally, except for taking video directly from the camera

    Regards!


  • Lifetime Qt Champion

    Did you check that you are using the API level 24 as indicated in the patch ?



  • @SGaist said in Display the QML screen on Ui :: MainWindow:

    Did you check that you are using the API level 24 as indicated in the patch ?

    Hi !
    I am using API30, but the integration of this suite is relatively complicated, because my English is limited, so I have not done this yet, I hope that next time there will be an easier approach. Thank you very much!



  • @SGaist
    Hi Sir !

    Is there any tutorial with Qt C ++?

    Thanks!


  • Lifetime Qt Champion

    Tutorial of what ?


Log in to reply