47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::MainWindow),
|
|
m_bCameraOpen(false),
|
|
mCamera(nullptr)
|
|
{
|
|
ui->setupUi(this);
|
|
std::vector<std::wstring> cameras = Camera::EnumAllCamera();
|
|
for(std::wstring x : cameras){
|
|
ui->comboBox->addItem(QString::fromWCharArray(x.c_str(),x.size()),
|
|
QString::fromWCharArray(x.c_str(),x.size()));
|
|
}
|
|
}
|
|
|
|
MainWindow::~MainWindow(){
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::on_pushButton_clicked(){
|
|
if(nullptr == mPlayerWidget){
|
|
mPlayerWidget = new CPlayWidget(nullptr);
|
|
}
|
|
if(!m_bCameraOpen){
|
|
mPlayerWidget->SetDataType(CPlayWidget::IMG_TYPE::TYPE_RGB32);
|
|
mPlayerWidget->SetImgSize(640,480);
|
|
|
|
qDebug()<<ui->comboBox->currentText().size()<<ui->comboBox->currentText();
|
|
wchar_t *opencamera = new wchar_t[ui->comboBox->currentText().size()];
|
|
ui->comboBox->currentText().toWCharArray(opencamera);
|
|
wstring ss = wstring(opencamera,ui->comboBox->currentText().size());
|
|
if(nullptr == mCamera){
|
|
this->mCamera = new Camera(ss);
|
|
}
|
|
this->mCamera->SetObserver(mPlayerWidget);
|
|
qDebug()<<ui->comboBox->currentText();
|
|
ui->pushButton->setText("关闭摄像头");
|
|
m_bCameraOpen = true;
|
|
mPlayerWidget->show();
|
|
}else{
|
|
m_bCameraOpen = false;
|
|
ui->pushButton->setText("打开摄像头");
|
|
}
|
|
}
|