Reply
Thread Tools
Posts: 395 | Thanked: 509 times | Joined on Jan 2011 @ Brisbane, Australia
#1
Not sure what I'm doing wrong, I've used signals/slots before, but it doesn't seem to fire for me on this.

Trying to figure out how all the QCamera stuff works, so first step would be taking a picture and saving it to file.

If anyone would have a clue as to why the imageSaved() isn't firing (I've tried it on a bunch of different signals, tried it with the QCamera::Status and State, it never gets fired for whatever I set it as).

Qt documentation isn't much help, their example they give explains nothing, doesn't tell you how the file is saved (if at all), if at all or where to set the file location or names (or I've just missed it).

Code:
private slots:
    void on_pushButton_clicked();
    void cap(int par1, QString par2);
Code:
void MainWindow::on_pushButton_clicked()
{
    QCamera *camera = new QCamera(QCamera::availableDevices().at(0));
    //QCameraViewfinder *viewFinder = new QCameraViewfinder;
    //camera->setViewfinder(viewFinder);
    //viewFinder->show();

    imageCapture = new QCameraImageCapture(camera);
    connect(imageCapture, SIGNAL(imageSaved(int,QString)), this, SLOT(cap(int,QString)));
    imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);

    QImageEncoderSettings imageSettings;
    imageSettings.setCodec("image/jpeg");
    imageSettings.setResolution(640, 480);
    qDebug() << imageSettings.resolution();

    imageCapture->setEncodingSettings(imageSettings);

    camera->setCaptureMode(QCamera::CaptureStillImage);
    camera->start();

    //on half pressed shutter button
    camera->searchAndLock();

    //connect(imageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(cap(int,QImage)));
    //on shutter button pressed
    imageCapture->capture();

    //on shutter button released
    camera->unlock();

    qDebug() << "done";
}

void MainWindow::cap(int par1, QString par2){
    qDebug() << "captured";
}
 
Copernicus's Avatar
Posts: 1,986 | Thanked: 7,698 times | Joined on Dec 2010 @ Dayton, Ohio
#2
Hmm. I think most camera apps today are by default going to use the "Design rule for Camera File" system, so all the pictures are going to be stored in the DCIM directory. That'd be the place to look to confirm if a file has been created or not.

I haven't tried using the QCamera or QCameraImageCapture before, but it looks to me like most of the functions -- start(), searchAndLock(), capture(), etc. -- are non-blocking. So, after running "start()", you can't immediately call "searchAndLock()"; you have to instead catch the appropriate "stateChanged()" signal, and fire the call once you've gotten that. And then catch a signal from that one in order to call "capture()", etc.

Also, both objects appear to have an "error()" signal, which might be helpful to connect; there's probably some useful info coming back from them.

EDIT: Hmm, yeah, their example code doesn't show them waiting for signals. Maybe these methods do block...

EDIT2: Ah, no, their example is simply incomplete (and annoyingly so). Instead of actually giving you a working example, they give you pieces of an example, along with comments (like "on shutter button pressed") that hint at what the rest of the code should be (such as connecting to a shutter button pressed signal)...

Last edited by Copernicus; 2014-04-15 at 12:05. Reason: I might be wrong
 

The Following User Says Thank You to Copernicus For This Useful Post:
Posts: 395 | Thanked: 509 times | Joined on Jan 2011 @ Brisbane, Australia
#3
Ended up finding another example, also figured out how along what exactly "saves" the file.

the ->capture has an optional param for location, so ->capture("/home/user/etcetc")

Anywho, I've got the QCamera going to a slot for when the status changes to "Active", then it tries the ->capture. Also added an error slot, which ends up shooting out "QCameraImageCapture::NotReadyError".

Now to figure out why it's not ready
 

The Following User Says Thank You to azkay For This Useful Post:
Posts: 395 | Thanked: 509 times | Joined on Jan 2011 @ Brisbane, Australia
#4
Got it!

Thanks for the awesome idea of checking the error signal :P

Code:
connect(m_stillImageCapture, SIGNAL(readyForCaptureChanged(bool)), this, SLOT(ready(bool)));
When ready() gets called with true, it lets me ->capture().
Awesomeeee.
 

The Following User Says Thank You to azkay For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 09:21.