Я получаю черный экран вместо изображения с камеры в графическом интерфейсе, который я делаю в QT - PullRequest
0 голосов
/ 31 мая 2019

Я получаю черный экран вместо прямой трансляции с камеры. Я не уверен, что не так с моим кодом, это первый раз, когда я использовал qt.Я получаю сообщение об ошибке во время выполнения, которое говорит следующее:

Невозможно запросить информацию о параметре: «Неверный аргумент»

Это мой код:

CameraTest.pro

#-------------------------------------------------
#
# Project created by QtCreator 2019-05-28T10:25:20
#
#-------------------------------------------------

QT       += core gui multimedia multimediawidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = CameraTest
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        widget.cpp

HEADERS += \
        widget.h

FORMS += \
        widget.ui
QMAKE_CXXFLAGS += -std=gnu++14

////////////////////////////////////////////////// widget.h

namespace Ui {
class Widget;
}
class QCamera;
class QCameraViewfinder;
class QCameraImageCapture;
class QVBoxLayout;
class QMenu;
class QAction;





class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    Ui::Widget *ui;
    QCamera * mCamera;
    QCameraViewfinder *mCameraViewfinder;
    QCameraImageCapture *mCameraImageCapture;
    QVBoxLayout *mLayout;
    QMenu *mOptionsMenu;
    QAction *mCameraAction;
    QAction *mGantryAction;
    QAction *mCaptureAction;
    QAction *mLazerAction;
};

#endif // WIDGET_H

///////////////////////////////////////////////////

main.cpp

#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setStyle("fusion");
    Widget w;
    w.show();

    return a.exec();
}
//////////////////////////////////////////////////

widget.cpp
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QVBoxLayout>
#include <QMenu>
#include <QAction>
#include <QFileDialog>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    mCamera = new QCamera(this);
    mCameraViewfinder = new QCameraViewfinder(this);
    mCameraImageCapture = new QCameraImageCapture(mCamera,this);
    mLayout = new QVBoxLayout;
    mOptionsMenu = new QMenu("Options",this);
    mCameraAction = new QAction("Camera",this);
    mGantryAction = new QAction("Gantry", this);
    mCaptureAction = new QAction("Capture",this);
    mLazerAction = new QAction("Lazer",this);
    mOptionsMenu->addActions({mCameraAction,mGantryAction,
                               mLazerAction});
    ui->optionsPushButton->setMenu(mOptionsMenu);
    ui->lazerDistance->setLayout(mLayout);

    ui->xAxis->setLayout(mLayout);
    ui->yAxis->setLayout(mLayout);
    ui->zAxis->setLayout(mLayout);
    ui->xRotate->setLayout(mLayout);
    ui->yRotate->setLayout(mLayout);
    ui->zRotate->setLayout(mLayout);
    ui->x1Label->setLayout(mLayout);
    ui->y1Label->setLayout(mLayout);
    ui->z1Label->setLayout(mLayout);
    ui->x2Label->setLayout(mLayout);
    ui->y2Label->setLayout(mLayout);
    ui->z2Label->setLayout(mLayout);
    ui->xAxis->hide();
    ui->yAxis->hide();
    ui->zAxis->hide();
    ui->xRotate->hide();
    ui->yRotate->hide();
    ui->zRotate->hide();
    ui->x1Label->hide();
    ui->y1Label->hide();
    ui->z1Label->hide();
    ui->x2Label->hide();
    ui->y2Label->hide();
    ui->z2Label->hide();
    ui->lazerDistance->hide();
    ui->scanButton->hide();
    ui->ScrollArea->hide();
    ui->scrollAreaWidgetContents->hide();
    mCameraViewfinder->hide();
    connect(mCameraAction, &QAction::triggered, [&](){
        ui->xAxis->hide();
        ui->yAxis->hide();
        ui->zAxis->hide();
        ui->xRotate->hide();
        ui->yRotate->hide();
        ui->zRotate->hide();
        ui->x1Label->hide();
        ui->y1Label->hide();
        ui->z1Label->hide();
        ui->x2Label->hide();
        ui->y2Label->hide();
        ui->z2Label->hide();
        ui->lazerDistance->hide();
        ui->scanButton->hide();
        mCamera->setViewfinder(mCameraViewfinder);
        mLayout->addWidget(mCameraViewfinder);
        mLayout->setMargin(0);
        ui->ScrollArea->setLayout(mLayout);
        ui->ScrollArea->show();
        ui->scrollAreaWidgetContents->show();
        mCameraViewfinder->show();
        mCamera->start();

      });

        connect(mGantryAction,&QAction::triggered, [&](){
           mCamera->stop();
         ui->ScrollArea->hide();
          ui->scrollAreaWidgetContents->hide();
          mCameraViewfinder->hide();
          ui->lazerDistance->hide();
          ui->scanButton->hide();



            ui->x1Label->show();
            ui->y1Label->show();
            ui->z1Label->show();
            ui->x2Label->show();
            ui->y2Label->show();
            ui->z2Label->show();
            ui->xAxis->show();
            ui->yAxis->show();
            ui->zAxis->show();
            ui->xRotate->show();
            ui->yRotate->show();
            ui->zRotate->show();
            ui->scanButton->show();

        });

    connect(mLazerAction, &QAction::triggered, [&](){
        mCamera->stop();
        ui->ScrollArea->hide();
        ui->scrollAreaWidgetContents->hide();
        mCameraViewfinder->hide();
        ui->scanButton->hide();
        ui->xAxis->hide();
        ui->yAxis->hide();
        ui->zAxis->hide();
        ui->xRotate->hide();
        ui->yRotate->hide();
        ui->zRotate->hide();
        ui->x1Label->hide();
        ui->y1Label->hide();
        ui->z1Label->hide();
        ui->x2Label->hide();
        ui->y2Label->hide();
        ui->z2Label->hide();

        ui->lazerDistance->show();






    });

}






Widget::~Widget()
{
    delete ui;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...