Perhaps it is something about the event handler. If I set the label to one of the stored pixmaps in the constructor, it works. I see the image. But the captured frame still crashes it.
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),
frame(640, 480),
pix_no(0)
{
ui->setupUi(this);
frame.load("campix1.jpg");
ui->label->setPixmap(frame);
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
cam = new QCamera(cameras.first(), this);
cam->load();
frame_grabber = new CameraFrameGrabber();
cam->setViewfinder(frame_grabber);
cam->setCaptureMode(QCamera::CaptureViewfinder);
connect(frame_grabber,
SIGNAL(frameAvailable
(QImage)),
this,
SLOT(handleFrame
(QImage)));
cam->start();
frame_timer.start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::handleFrame(const QImage& img)
{
frame_times.push_back(frame_timer.elapsed());
frame_timer.restart();
if (frame_times.size() > 10) frame_times.pop_front();
int frame_count = frame_times.size();
int frame_total = 0;
for(int i = 0; i < frame_count; ++i)
{
frame_total += frame_times[i];
}
double fps = 0;
if (frame_count)
{
fps = (frame_total / frame_count);
}
ui->sb_fps->setValue(fps);
fname
+= QString::number(++pix_no
);
fname += ".jpg";
bool success = frame.save(fname);
ui->label->setPixmap(frame);
this->update();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
frame(640, 480),
pix_no(0)
{
ui->setupUi(this);
frame.load("campix1.jpg");
ui->label->setPixmap(frame);
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
cam = new QCamera(cameras.first(), this);
cam->load();
frame_grabber = new CameraFrameGrabber();
cam->setViewfinder(frame_grabber);
cam->setCaptureMode(QCamera::CaptureViewfinder);
connect(frame_grabber, SIGNAL(frameAvailable(QImage)), this, SLOT(handleFrame(QImage)));
cam->start();
frame_timer.start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::handleFrame(const QImage& img)
{
frame_times.push_back(frame_timer.elapsed());
frame_timer.restart();
if (frame_times.size() > 10) frame_times.pop_front();
int frame_count = frame_times.size();
int frame_total = 0;
for(int i = 0; i < frame_count; ++i)
{
frame_total += frame_times[i];
}
double fps = 0;
if (frame_count)
{
fps = (frame_total / frame_count);
}
ui->sb_fps->setValue(fps);
frame = QPixmap::fromImage(img);
QString fname("campix");
fname += QString::number(++pix_no);
fname += ".jpg";
bool success = frame.save(fname);
ui->label->setPixmap(frame);
this->update();
}
To copy to clipboard, switch view to plain text mode
This is the stack while stopped at a breakpoint in the handleFrame event.
1 MainWindow::handleFrame mainwindow.cpp 62 0x7ff6d7082e44
2 MainWindow::qt_static_metacall moc_mainwindow.cpp 73 0x7ff6d7087bb5
5 CameraFrameGrabber::frameAvailable moc_cameraframegrabber.cpp 128 0x7ff6d7087f1b
6 CameraFrameGrabber::present cameraframegrabber.cpp 56 0x7ff6d7086e00
7 DSCameraSession::presentFrame dscamerasession.cpp 683 0x7ffc074ca264
8 DSCameraSession::qt_static_metacall moc_dscamerasession.cpp 111 0x7ffc074da2e6
9 QMetaCallEvent::placeMetaCall qobject.cpp 503 0x5d156c81
10 QObject::event qobject.
cpp 1263 0x5d14f6df
11 QApplicationPrivate::notify_helper qapplication.cpp 3799 0x5d8a5e8e
15 QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp 1649 0x5d0f9112
16 QEventDispatcherWin32::sendPostedEvents qeventdispatcher_win.cpp 1295 0x5d1b180a
17 QWindowsGuiEventDispatcher::sendPostedEvents qwindowsguieventdispatcher.cpp 82 0x7ffbfc70c204
18 qt_internal_proc qeventdispatcher_win.cpp 445 0x5d1af521
19 CallWindowProcW USER32 0x7ffc29f41c24
20 DispatchMessageW USER32 0x7ffc29f4156c
21 QEventDispatcherWin32::processEvents qeventdispatcher_win.cpp 845 0x5d1aff2b
22 QWindowsGuiEventDispatcher::processEvents qwindowsguieventdispatcher.cpp 74 0x7ffbfc70c1c4
23 QEventLoop::processEvents qeventloop.
cpp 135 0x5d0f24e8
26 QGuiApplication::exec qguiapplication.cpp 1640 0x7ffbfccf3208
28 main main.cpp 10 0x7ff6d7082749
29 WinMain qtmain_win.cpp 123 0x7ff6d708afbd
30 invoke_main exe_common.inl 109 0x7ff6d7088bed
31 __scrt_common_main_seh exe_common.inl 264 0x7ff6d7088a8e
32 __scrt_common_main exe_common.inl 309 0x7ff6d708894e
33 WinMainCRTStartup exe_winmain.cpp 17 0x7ff6d7088c09
34 BaseThreadInitThunk KERNEL32 0x7ffc2a4a8364
35 RtlUserThreadStart ntdll 0x7ffc2c1a5e91
1 MainWindow::handleFrame mainwindow.cpp 62 0x7ff6d7082e44
2 MainWindow::qt_static_metacall moc_mainwindow.cpp 73 0x7ff6d7087bb5
3 QMetaObject::activate qobject.cpp 3742 0x5d14daf2
4 QMetaObject::activate qobject.cpp 3603 0x5d14d268
5 CameraFrameGrabber::frameAvailable moc_cameraframegrabber.cpp 128 0x7ff6d7087f1b
6 CameraFrameGrabber::present cameraframegrabber.cpp 56 0x7ff6d7086e00
7 DSCameraSession::presentFrame dscamerasession.cpp 683 0x7ffc074ca264
8 DSCameraSession::qt_static_metacall moc_dscamerasession.cpp 111 0x7ffc074da2e6
9 QMetaCallEvent::placeMetaCall qobject.cpp 503 0x5d156c81
10 QObject::event qobject.cpp 1263 0x5d14f6df
11 QApplicationPrivate::notify_helper qapplication.cpp 3799 0x5d8a5e8e
12 QApplication::notify qapplication.cpp 3159 0x5d8a0713
13 QCoreApplication::notifyInternal2 qcoreapplication.cpp 988 0x5d0f78c6
14 QCoreApplication::sendEvent qcoreapplication.h 231 0x5d1027f2
15 QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp 1649 0x5d0f9112
16 QEventDispatcherWin32::sendPostedEvents qeventdispatcher_win.cpp 1295 0x5d1b180a
17 QWindowsGuiEventDispatcher::sendPostedEvents qwindowsguieventdispatcher.cpp 82 0x7ffbfc70c204
18 qt_internal_proc qeventdispatcher_win.cpp 445 0x5d1af521
19 CallWindowProcW USER32 0x7ffc29f41c24
20 DispatchMessageW USER32 0x7ffc29f4156c
21 QEventDispatcherWin32::processEvents qeventdispatcher_win.cpp 845 0x5d1aff2b
22 QWindowsGuiEventDispatcher::processEvents qwindowsguieventdispatcher.cpp 74 0x7ffbfc70c1c4
23 QEventLoop::processEvents qeventloop.cpp 135 0x5d0f24e8
24 QEventLoop::exec qeventloop.cpp 210 0x5d0f272e
25 QCoreApplication::exec qcoreapplication.cpp 1261 0x5d0f55ff
26 QGuiApplication::exec qguiapplication.cpp 1640 0x7ffbfccf3208
27 QApplication::exec qapplication.cpp 2976 0x5d8a021a
28 main main.cpp 10 0x7ff6d7082749
29 WinMain qtmain_win.cpp 123 0x7ff6d708afbd
30 invoke_main exe_common.inl 109 0x7ff6d7088bed
31 __scrt_common_main_seh exe_common.inl 264 0x7ff6d7088a8e
32 __scrt_common_main exe_common.inl 309 0x7ff6d708894e
33 WinMainCRTStartup exe_winmain.cpp 17 0x7ff6d7088c09
34 BaseThreadInitThunk KERNEL32 0x7ffc2a4a8364
35 RtlUserThreadStart ntdll 0x7ffc2c1a5e91
To copy to clipboard, switch view to plain text mode
Bookmarks