[libcamera-devel] [PATCH 12/21] qcam: Use Qt qInfo() and qWarning() logging facilities
Kieran Bingham
kieran.bingham at ideasonboard.com
Mon Mar 23 16:45:09 CET 2020
Hi Laurent,
On 23/03/2020 15:27, Laurent Pinchart wrote:
> Hi Kieran,
>
> On Mon, Mar 23, 2020 at 02:56:06PM +0000, Kieran Bingham wrote:
>> On 23/03/2020 14:21, Laurent Pinchart wrote:
>>> Replace manual usage of std::cout and std::cerr with the Qt logging
>>> facilities. This allows redirection log output if needed, and integrates
>>> better with Qt.
>>
>> This fails to compile for me...
>>
>>> [2/3] Compiling C++ object 'src/qcam/9916d8b@@qcam at exe/main_window.cpp.o'.
>>> FAILED: src/qcam/9916d8b@@qcam at exe/main_window.cpp.o
>>> ccache c++ -Isrc/qcam/9916d8b@@qcam at exe -Isrc/qcam -I../src/qcam -Iinclude -I../include -Iinclude/libcamera -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I/usr/include/x86_64-linux-gnu/qt5 -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Werror -std=c++14 -g -Wno-unused-parameter -include config.h -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -fPIC -DQT_NO_KEYWORDS -MD -MQ 'src/qcam/9916d8b@@qcam at exe/main_window.cpp.o' -MF 'src/qcam/9916d8b@@qcam at exe/main_window.cpp.o.d' -o 'src/qcam/9916d8b@@qcam at exe/main_window.cpp.o' -c ../src/qcam/main_window.cpp
>>> ../src/qcam/main_window.cpp: In member function ‘void MainWindow::processCapture()’:
>>> ../src/qcam/main_window.cpp:516:31: error: ‘reset’ is not a member of ‘Qt’
>>> << metadata.sequence << Qt::reset
>>> ^~~~~
>>> ../src/qcam/main_window.cpp:516:31: note: suggested alternative:
>>> In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qdebug.h:49,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtCore/QtDebug:1,
>>> from ../src/qcam/main_window.cpp:26:
>>> /usr/include/x86_64-linux-gnu/qt5/QtCore/qtextstream.h:262:28: note: ‘reset’
>>> Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
>>> ^~~~~
>>> ../src/qcam/main_window.cpp:519:20: error: ‘fixed’ is not a member of ‘Qt’
>>> << "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps;
>>> ^~~~~
>>> ../src/qcam/main_window.cpp:519:20: note: suggested alternatives:
>>> In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qdebug.h:49,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtCore/QtDebug:1,
>>> from ../src/qcam/main_window.cpp:26:
>>> /usr/include/x86_64-linux-gnu/qt5/QtCore/qtextstream.h:253:28: note: ‘fixed’
>>> Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
>>> ^~~~~
>>> In file included from /usr/include/c++/8/ios:42,
>>> from /usr/include/c++/8/ostream:38,
>>> from /usr/include/c++/8/iterator:64,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:53,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:49,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:47,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qwidget.h:45,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qmainwindow.h:44,
>>> from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/QMainWindow:1,
>>> from ../src/qcam/main_window.h:13,
>>> from ../src/qcam/main_window.cpp:8:
>>> /usr/include/c++/8/bits/ios_base.h:1043:3: note: ‘std::fixed’
>>> fixed(ios_base& __base)
>>> ^~~~~
>>> ninja: build stopped: subcommand failed.
>>> make: *** [m:24: libcamera] Error 1
>
> It seems to be a Qt version issue. Could you try to remove the Qt::
> prefix from reset and fixed ?
That appears to have fixed things yes,
>
>>> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
>>> ---
>>> src/qcam/main.cpp | 8 +++----
>>> src/qcam/main_window.cpp | 45 ++++++++++++++++++++--------------------
>>> 2 files changed, 26 insertions(+), 27 deletions(-)
>>>
>>> diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
>>> index 297453914ae9..862d714f467c 100644
>>> --- a/src/qcam/main.cpp
>>> +++ b/src/qcam/main.cpp
>>> @@ -5,11 +5,11 @@
>>> * main.cpp - cam - The libcamera swiss army knife
>>> */
>>>
>>> -#include <iostream>
>>> #include <signal.h>
>>> #include <string.h>
>>>
>>> #include <QApplication>
>>> +#include <QtDebug>
>>>
>>> #include <libcamera/camera_manager.h>
>>>
>>> @@ -18,7 +18,7 @@
>>>
>>> void signalHandler(int signal)
>>> {
>>> - std::cout << "Exiting" << std::endl;
>>> + qInfo() << "Exiting";
>>> qApp->quit();
>>> }
>>>
>>> @@ -65,8 +65,8 @@ int main(int argc, char **argv)
>>>
>>> ret = cm->start();
>>> if (ret) {
>>> - std::cout << "Failed to start camera manager: "
>>> - << strerror(-ret) << std::endl;
>>> + qInfo() << "Failed to start camera manager:"
>>> + << strerror(-ret);
>>> return EXIT_FAILURE;
>>> }
>>>
>>> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
>>> index ed8301502fb2..184345b0e2a6 100644
>>> --- a/src/qcam/main_window.cpp
>>> +++ b/src/qcam/main_window.cpp
>>> @@ -8,7 +8,6 @@
>>> #include "main_window.h"
>>>
>>> #include <iomanip>
>>> -#include <iostream>
>>> #include <string>
>>> #include <sys/mman.h>
>>>
>>> @@ -24,6 +23,7 @@
>>> #include <QTimer>
>>> #include <QToolBar>
>>> #include <QToolButton>
>>> +#include <QtDebug>
>>>
>>> #include <libcamera/camera_manager.h>
>>> #include <libcamera/version.h>
>>> @@ -177,11 +177,11 @@ void MainWindow::switchCamera(int index)
>>> const std::shared_ptr<Camera> &cam = cameras[index];
>>>
>>> if (cam->acquire()) {
>>> - std::cout << "Failed to acquire camera " << cam->name() << std::endl;
>>> + qInfo() << "Failed to acquire camera" << cam->name().c_str();
>>> return;
>>> }
>>>
>>> - std::cout << "Switching to camera " << cam->name() << std::endl;
>>> + qInfo() << "Switching to camera" << cam->name().c_str();
>>>
>>> /*
>>> * Stop the capture session, release the current camera, replace it with
>>> @@ -236,13 +236,12 @@ int MainWindow::openCamera()
>>> /* Get and acquire the camera. */
>>> camera_ = cm_->get(cameraName);
>>> if (!camera_) {
>>> - std::cout << "Camera " << cameraName << " not found"
>>> - << std::endl;
>>> + qInfo() << "Camera" << cameraName.c_str() << "not found";
>>> return -ENODEV;
>>> }
>>>
>>> if (camera_->acquire()) {
>>> - std::cout << "Failed to acquire camera" << std::endl;
>>> + qInfo() << "Failed to acquire camera";
>>> camera_.reset();
>>> return -EBUSY;
>>> }
>>> @@ -296,18 +295,18 @@ int MainWindow::startCapture()
>>>
>>> CameraConfiguration::Status validation = config_->validate();
>>> if (validation == CameraConfiguration::Invalid) {
>>> - std::cerr << "Failed to create valid camera configuration";
>>> + qWarning() << "Failed to create valid camera configuration";
>>> return -EINVAL;
>>> }
>>>
>>> if (validation == CameraConfiguration::Adjusted) {
>>> - std::cout << "Stream size adjusted to "
>>> - << cfg.size.toString() << std::endl;
>>> + qInfo() << "Stream size adjusted to"
>>> + << cfg.size.toString().c_str();
>>> }
>>>
>>> ret = camera_->configure(config_.get());
>>> if (ret < 0) {
>>> - std::cout << "Failed to configure camera" << std::endl;
>>> + qInfo() << "Failed to configure camera";
>>> return ret;
>>> }
>>>
>>> @@ -316,7 +315,7 @@ int MainWindow::startCapture()
>>> ret = viewfinder_->setFormat(cfg.pixelFormat,
>>> QSize(cfg.size.width, cfg.size.height));
>>> if (ret < 0) {
>>> - std::cout << "Failed to set viewfinder format" << std::endl;
>>> + qInfo() << "Failed to set viewfinder format";
>>> return ret;
>>> }
>>>
>>> @@ -326,7 +325,7 @@ int MainWindow::startCapture()
>>> allocator_ = new FrameBufferAllocator(camera_);
>>> ret = allocator_->allocate(stream);
>>> if (ret < 0) {
>>> - std::cerr << "Failed to allocate capture buffers" << std::endl;
>>> + qWarning() << "Failed to allocate capture buffers";
>>> return ret;
>>> }
>>>
>>> @@ -334,14 +333,14 @@ int MainWindow::startCapture()
>>> for (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) {
>>> Request *request = camera_->createRequest();
>>> if (!request) {
>>> - std::cerr << "Can't create request" << std::endl;
>>> + qWarning() << "Can't create request";
>>> ret = -ENOMEM;
>>> goto error;
>>> }
>>>
>>> ret = request->addBuffer(stream, buffer.get());
>>> if (ret < 0) {
>>> - std::cerr << "Can't set buffer for request" << std::endl;
>>> + qWarning() << "Can't set buffer for request";
>>> goto error;
>>> }
>>>
>>> @@ -364,7 +363,7 @@ int MainWindow::startCapture()
>>>
>>> ret = camera_->start();
>>> if (ret) {
>>> - std::cout << "Failed to start capture" << std::endl;
>>> + qInfo() << "Failed to start capture";
>>> goto error;
>>> }
>>>
>>> @@ -374,7 +373,7 @@ int MainWindow::startCapture()
>>> for (Request *request : requests) {
>>> ret = camera_->queueRequest(request);
>>> if (ret < 0) {
>>> - std::cerr << "Can't queue request" << std::endl;
>>> + qWarning() << "Can't queue request";
>>> goto error_disconnect;
>>> }
>>> }
>>> @@ -417,7 +416,7 @@ void MainWindow::stopCapture()
>>>
>>> int ret = camera_->stop();
>>> if (ret)
>>> - std::cout << "Failed to stop capture" << std::endl;
>>> + qInfo() << "Failed to stop capture";
>>>
>>> camera_->requestCompleted.disconnect(this, &MainWindow::requestComplete);
>>>
>>> @@ -513,11 +512,11 @@ void MainWindow::processCapture()
>>> fps = lastBufferTime_ && fps ? 1000000000.0 / fps : 0.0;
>>> lastBufferTime_ = metadata.timestamp;
>>>
>>> - std::cout << "seq: " << std::setw(6) << std::setfill('0') << metadata.sequence
>>> - << " bytesused: " << metadata.planes[0].bytesused
>>> - << " timestamp: " << metadata.timestamp
>>> - << " fps: " << std::fixed << std::setprecision(2) << fps
>>> - << std::endl;
>>> + qInfo() << "seq:" << qSetFieldWidth(6) << qSetPadChar('0')
>>> + << metadata.sequence << Qt::reset
>>> + << "bytesused:" << metadata.planes[0].bytesused
>>> + << "timestamp:" << metadata.timestamp
>>> + << "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps;
>>>
>>> /* Display the buffer and requeue it to the camera. */
>>> display(buffer);
>>> @@ -542,7 +541,7 @@ void MainWindow::queueRequest(FrameBuffer *buffer)
>>> {
>>> Request *request = camera_->createRequest();
>>> if (!request) {
>>> - std::cerr << "Can't create request" << std::endl;
>>> + qWarning() << "Can't create request";
>>> return;
>>> }
>>>
>
--
Regards
--
Kieran
More information about the libcamera-devel
mailing list