PDA

View Full Version : Display camera in a GridLayout



nils90
30th November 2015, 17:41
Hey !

I am trying to display what my webcam views in a gridLayout. Here is my code : it compiles but doesn't work : it display a window with the different buttons but not the video from my camera. Can anyone help me to make it work ? I have already seen the Qt documentation and Qt examples but it didn't help me. I am a very beginner in Qt. I work on Windows and Qt5.



#include "fenetre.h"

Fenetre::Fenetre(): QWidget()
{

m_up= new QPushButton("up", this);
m_right= new QPushButton("right", this);
m_down= new QPushButton("down", this);
m_left= new QPushButton("left", this);
m_mode= new QPushButton("deplacement", this);

//QLabel *image = new QLabel(this);
//image->setPixmap(QPixmap("smile.png"));

camera = new QCamera;
cvf = new QCameraViewfinder;
camera->start();


layout = new QGridLayout;
layout-> addWidget(m_up,0,1);
layout-> addWidget(m_right,1,2);
layout-> addWidget(m_down,2,1);
layout-> addWidget(m_left,1,0);
layout-> addWidget(m_mode,0,0);
//layout->addWidget(image,1,1);
layout-> addWidget(cvf,1,1);
setLayout(layout);

QObject::connect(m_mode, SIGNAL(clicked()), this, SLOT(changerMode()));
}

void Fenetre::changerMode()
{
if (m_mode->text()=="deplacement")
{
m_up->setText("accelerer");
m_down->setText("ralentir");
m_mode->setText("vision");
}
else
{
m_up->setText("up");
m_down->setText("down");
m_mode->setText("deplacement");
}
}




Thank you very much for your help !

d_stranz
1st December 2015, 03:28
And where do you call QCameraViewfinder::setMediaObject() with the pointer to your QCamera instance? Did you expect the viewfinder to look around in your code for a camera and magically hook up to it?