2017-03-01 49 views
0

這是關於使用小部件安排多媒體對象。 下面是我曾嘗試:如何安排QCamera與佈局中的其他小部件?

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

QCamera本身不是一個小部件!但是從the qt doc我們瞭解到:

「QCamera可與QCameraViewfinder一起用於取景器顯示,QMediaRecorder用於視頻錄製,QCameraImageCapture用於拍攝圖像。」

所以我想你想可能是一個QCameraViewfinder什麼:

QCameraViewfinder* cameraView = new QCameraViewfinder (this); 

cameraView->setMediaObject (m_QCamera_required_camera); 

layout->addWidget(cameraView); 
1

QCamera不是一個小部件,你應該使用一個QCameraViewfinder(添加multimediawidgets到的.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