如何在布局中安排QCamera与其他小部件?

时间:2017-03-01 07:13:02

标签: c++ qt qlayout qtmultimedia

这是关于使用小部件安排多媒体对象。 以下是我的尝试:

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    m_QPushButton_calibration = new QPushButton("Calibrate", this);
    connect(m_QPushButton_calibration, SIGNAL (released()),this, SLOT (handleButton()));


    QList<QCameraInfo> l_QListQCameraInfo_available_cameras = QCameraInfo::availableCameras();
    if (l_QListQCameraInfo_available_cameras.length() > 2)
    {
        m_QCamera_required_camera = new QCamera (l_QListQCameraInfo_available_cameras[1]);
    }

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(m_QPushButton_calibration);
    layout->addWidget(m_QCamera_required_camera);

    this->setLayout(layout);
}

结果是:

error: no matching function for call to 'QHBoxLayout::addWidget(QCamera*&)'
     layout->addWidget(m_QCamera_required_camera);
                                                ^

如何在布局中使用其他小部件安排QCamera?

2 个答案:

答案 0 :(得分:2)

QCamera本身不是一个小部件!但是从the qt doc我们学到了:

“QCamera可与QCameraViewfinder一起用于取景器显示,QMediaRecorder用于视频录制,QCameraImageCapture用于拍摄图像。”

所以我想你想要的可能是QCameraViewfinder:

QCameraViewfinder* cameraView = new QCameraViewfinder (this);

cameraView->setMediaObject (m_QCamera_required_camera);

layout->addWidget(cameraView);

答案 1 :(得分:1)

QCamera不是小部件,您应该使用QCameraViewfinder(将多媒体小部件添加到.pro):

QCameraViewfinder *mCameraViewfinder = new QCameraViewfinder(this);
m_QCamera_required_camera->setViewfinder(mCameraViewfinder);

layout->addWidget(m_QPushButton_calibration);
layout->addWidget(mCameraViewfinder);
m_QCamera_required_camera->start();

Complete code