×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    95

    QWebView and camera: eerrreserve

    Hi all,
    i've a simple app that has 2 views:

    1) first view display a qwebview and a button to go to second view;
    2) second view display camera viewfinder and a button to go to first view;

    Now, if i load www.openstreetmap.org on qwebview and move, zoom, pan (generally execute any action on map on qwebview), when
    go to second view to see the camera viewfinder, sometimes i receive EErrReserve error from camera object.

    I have tryed to stop qwebview before go to second view but nothing.

    Sometimes i receive EErrReserve from camera object.

    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    #if defined(Q_WS_S60)
    w.showMaximized();
    #else
    w.show();
    #endif

    return a.exec();
    }




    #-------------------------------------------------
    #
    # Project created by QtCreator 2011-01-12T10:48:09
    #
    #-------------------------------------------------

    QT += core gui webkit network

    TARGET = TestCamera
    TEMPLATE = app


    SOURCES += main.cpp\
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS +=

    CONFIG += mobility
    MOBILITY =

    symbian {
    TARGET.UID3 = 0xe96e71cb
    TARGET.CAPABILITY += UserEnvironment NetworkServices
    TARGET.EPOCSTACKSIZE = 0x14000
    TARGET.EPOCHEAPSIZE = 0x020000 0x2000000

    LIBS += -lecam -lfbscli # use camera

    }






    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QLabel>
    #include <QWebView>
    #include <QNetworkReply>
    #include <QNetworkAccessManager>

    #ifdef Q_WS_S60
    #include <ecam.h>
    #include <fbs.h>
    #endif


    class MainWindow : public QMainWindow
    #ifdef Q_WS_S60
    , public MCameraObserver2
    #endif
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    public:
    void CreateFirstScreen();
    void CreateSecondScreen();
    void StartCamera();
    void StopCamera();

    private slots:
    void OnBtnGoToSecondScreenClicked();
    void OnBtnGoToFirstScreenClicked();

    private:
    QWidget *firstScreen;
    QWidget *secondScreen;
    QLabel *secondScreenImgPreview;

    /* CODE TO USE CAMERA */
    #ifdef Q_WS_S60
    private:
    void HandleEvent(const TECAMEvent& aEvent);
    void ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError);
    void ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError);
    void VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError);


    private:
    CCamera *iCamera;
    #endif

    };

    #endif // MAINWINDOW_H






    #include "mainwindow.h"
    #include <QGridLayout>
    #include <QPushButton>
    #include <QDebug>
    #include <QVBoxLayout>
    #include <QWebView>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    this->firstScreen = NULL;
    this->secondScreen = NULL;
    this->secondScreenImgPreview = NULL;

    #ifdef Q_WS_S60
    this->iCamera = NULL;
    #endif

    CreateFirstScreen();
    this->setCentralWidget(this->firstScreen);
    }


    MainWindow::~MainWindow()
    {
    }

    void MainWindow::CreateFirstScreen()
    {
    this->firstScreen = new QWidget(this);

    QVBoxLayout *layout = new QVBoxLayout(this->firstScreen);

    QWebView *webView = new QWebView(this->firstScreen);
    webView->load(QUrl("http://www.openstreetmap.org"));
    layout->addWidget(webView);


    QPushButton *btnGoToSecondScreen = new QPushButton(this->firstScreen);
    connect(btnGoToSecondScreen, SIGNAL(clicked()), this, SLOT(OnBtnGoToSecondScreenClicked()));
    btnGoToSecondScreen->setText("Go to second screen");
    layout->addWidget(btnGoToSecondScreen);
    this->firstScreen->setLayout(layout);

    }


    void MainWindow::OnBtnGoToSecondScreenClicked()
    {
    CreateSecondScreen();
    this->setCentralWidget(this->secondScreen);
    this->firstScreen = NULL;
    }

    void MainWindow::OnBtnGoToFirstScreenClicked()
    {
    StopCamera();

    CreateFirstScreen();
    this->setCentralWidget(this->firstScreen);
    this->secondScreen = NULL;
    }

    void MainWindow::CreateSecondScreen()
    {
    this->secondScreen = new QWidget(this);

    QVBoxLayout *layout = new QVBoxLayout(this->secondScreen);

    this->secondScreenImgPreview = new QLabel(this->secondScreen);
    layout->addWidget(this->secondScreenImgPreview);

    QPushButton *btnGoToFirstScreen = new QPushButton(this->secondScreen);
    connect(btnGoToFirstScreen, SIGNAL(clicked()), this, SLOT(OnBtnGoToFirstScreenClicked()));
    btnGoToFirstScreen->setText("Go to first screen");
    layout->addWidget(btnGoToFirstScreen);
    this->secondScreen->setLayout(layout);

    StartCamera();

    }

    void MainWindow::StartCamera()
    {
    #ifdef Q_WS_S60
    iCamera = CCamera::New2L(*this, 0, 0);
    iCamera->Reserve();
    #endif
    }

    void MainWindow::StopCamera()
    {
    #ifdef Q_WS_S60
    iCamera->StopViewFinder();
    iCamera->PowerOff();
    delete iCamera;
    iCamera = NULL;
    #endif
    }

    #ifdef Q_WS_S60
    void MainWindow::HandleEvent(const TECAMEvent& aEvent)
    {
    qDebug()<< "HandleEvent";

    qDebug() << "Error code: " << aEvent.iErrorCode;

    if (aEvent.iEventType == KUidECamEventReserveComplete)
    {
    //Reserve Complete
    qDebug()<<"Reserve Complete";
    iCamera->PowerOn();
    }

    if (aEvent.iEventType == KUidECamEventPowerOnComplete)
    {
    //PowerOn Complete
    qDebug()<<"PowerOn complete";

    TSize sz(240,180);
    iCamera->StartViewFinderBitmapsL(sz);
    }
    }

    void MainWindow::ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError)
    {
    qDebug() << "ViewFinderReady";
    CFbsBitmap bmp;
    bmp.Duplicate(aCameraBuffer.BitmapL(0).Handle());
    QPixmap pxm = QPixmap::fromSymbianCFbsBitmap(&bmp);

    this->secondScreenImgPreview->setPixmap(pxm);

    aCameraBuffer.Release();
    }

    void MainWindow::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
    {
    qDebug() << "ImageBufferReady";
    aCameraBuffer.Release();
    }

    void MainWindow::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
    {
    qDebug() << "VideoBufferReady";
    aCameraBuffer.Release();
    }
    #endif

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: QWebView and camera: eerrreserve

    in StartCamera() make sure you have iCamera as NULL

  3. #3
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    95

    Re: QWebView and camera: eerrreserve

    StartCamera() is launched when user goto second screen.

    Then iCamera object is destroyed when user return first screen (you can see code in OnBtnGoToFirstScreenClicked()).

    So iCamera will be always NULL at launch in StartCamera().

Similar Threads

  1. QWebView
    By atonical in forum Qt
    Replies: 1
    Last Post: 2011-02-13, 19:14
  2. Can't Paint On QWebView
    By pta0007 in forum Qt
    Replies: 6
    Last Post: 2010-09-08, 15:41
  3. Problem with QwebView
    By toto42toto in forum Qt
    Replies: 1
    Last Post: 2010-07-20, 13:07
  4. using QWebView class
    By prathibha83 in forum Qt
    Replies: 7
    Last Post: 2010-05-24, 06:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •