Qt World Summit: Submit your Presentation

qt sigfpe arithmetic exception

  • I'm pretty new to qt and i'm trying to create a widget that showing my webcam using qt and opencv. As the title has stated that i'm stuck at tracking the sigfpe arithmetic exception. The odd thing about this issues is that 2 days ago, my code worked, but now it's not. After doing some research, i discovered that this issues have been addressed in multiple topic, with multiple solving method, but i don't think it would work for me

    ok, lat me wrap things up a bit, when i run my code, the process ended forcefully, crashed. Then i run debugger, which indicated "sigfpe arithmetic exception" in line 6 (myvideocapture.cpp), line 10 (mainwindow.cpp) and line 8(main.cpp) i'll later mark the line for easier visualization

    here's my code:

    # Project created by QtCreator 2019-08-10T12:27:53
    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = TutorialOpenCV
    TEMPLATE = app
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    CONFIG += c++11
    SOURCES += \
            main.cpp \
            mainwindow.cpp \
    HEADERS += \
            mainwindow.h \
    FORMS += \
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../opencv/build/x64/vc15/lib/ -lopencv_world451
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../opencv/build/x64/vc15/lib/ -lopencv_world451d
    else:unix: LIBS += -L$$PWD/../../../../../opencv/build/x64/vc15/lib/ -lopencv_world451
    INCLUDEPATH += C:\opencv\build\x64\vc15
    LIBS += C:\opencv\build\x64\vc15\lib\opencv_world451.lib
    LIBS += C:\opencv\build\x64\vc15\lib\opencv_world451d.lib
    INCLUDEPATH += $$PWD/../../../../../opencv/build/include
    DEPENDPATH += $$PWD/../../../../../opencv/build/include
    INCLUDEPATH += C:\opencv\release\install\include
    LIBS += C:\opencv\release\bin\libopencv_core451.dll
    LIBS += C:\opencv\release\bin\libopencv_highgui451.dll
    LIBS += C:\opencv\release\bin\libopencv_imgcodecs451.dll
    LIBS += C:\opencv\release\bin\libopencv_imgproc451.dll
    LIBS += C:\opencv\release\bin\libopencv_features2d451.dll
    LIBS += C:\opencv\release\bin\libopencv_calib3d451.dll
    INCLUDEPATH += C:\opencv\release\install\include\opencv2
    INCLUDEPATH += C:\opencv\release\install\include\opencv
    INCLUDEPATH += C:\opencv\build\include
    INCLUDEPATH += C:\opencv\release\include
    LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_core451.dll
    LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_highgui451.dll
    LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_imgcodecs451.dll
    LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_imgproc451.dll
    LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_features2d451.dll
    LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_calib3d451.dll


    #include "myvideocapture.h"
    #include <QDebug>
    MyVideoCapture::MyVideoCapture(QObject *parent)
        : QThread { parent }
        , mVideoCap { ID_CAMERA }
    ///////////////////////this line///////////////////////////////
    void MyVideoCapture::run()
        if (mVideoCap.isOpened())
            while (true)
                mVideoCap >> mFrame;
                if (!mFrame.empty())
                    cv::rectangle(mFrame, cv::Point(10, 10), cv::Point(401, 401), cv::Scalar(0, 0, 255), 1);
                    mPixmap = cvMatToQPixmap(mFrame);
                    emit newPixmapCaptured();
    QImage MyVideoCapture::cvMatToQImage(const cv::Mat &inMat)
        switch (inMat.type())
            // 8-bit, 4 channel
            case CV_8UC4:
                QImage image(inMat.data, inMat.cols, inMat.rows, static_cast<int>(inMat.step), QImage::Format_ARGB32);
                return image;
            // 8-bit, 3 channel
            case CV_8UC3:
                QImage image(inMat.data, inMat.cols, inMat.rows, static_cast<int>(inMat.step), QImage::Format_RGB888);
                return image.rgbSwapped();
            // 8-bit, 1 channel
            case CV_8UC1:
        #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
                QImage image(inMat.data, inMat.cols, inMat.rows, static_cast<int>(inMat.step), QImage::Format_Grayscale8);
                static QVector<QRgb>  sColorTable;
                // only create our color table the first time
                if (sColorTable.isEmpty())
                    sColorTable.resize(256 );
                    for (int i = 0; i < 256; ++i )
                        sColorTable[i] = qRgb(i, i, i );
                QImage image(inMat.data,
                             inMat.cols, inMat.rows,
                             QImage::Format_Indexed8 );
                image.setColorTable(sColorTable );
                return image;
                qWarning()<< "ASM::cvMatToQImage()- cv::Mat image type not handled in switch:" << inMat.type();
        return QImage();
    QPixmap MyVideoCapture::cvMatToQPixmap(const cv::Mat &inMat)
        return QPixmap::fromImage(cvMatToQImage(inMat));


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "myvideocapture.h"
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        mOpenCV_videoCapture = new MyVideoCapture(this);
    ////////////////////////this line////////////////////////////////
        connect(mOpenCV_videoCapture, &MyVideoCapture::newPixmapCaptured, this, [&]()
            ui->opencvFrame->setPixmap(mOpenCV_videoCapture->pixmap().scaled(500, 500));
        delete ui;
    void MainWindow::on_iniciarOpenCV_button_clicked()


    #include "mainwindow.h"
    #include <QApplication>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;
    ////////////////////this line///////////////////////////
        return a.exec();

  • Lifetime Qt Champion

    As always when a crash happens - use a debugger to see where and why it crashes.

  • Lifetime Qt Champion

    @NoobDude12343 said in qt sigfpe arithmetic exception:

    ui->opencvFrame->setPixmap(mOpenCV_videoCapture->pixmap().scaled(500, 500));

    And this creates a race condition since two threads may access this data. Send the image/pixmap via signals/slots instead.

  • thanks for replying @Christian-Ehrlicher , now i face another error, which is "lnk1107 invalid or corrupt file cannot read 0x458"
    i google this and couldn't found anything, not the 0x458 particularly, any insight?

  • Lifetime Qt Champion

    @NoobDude12343 said in qt sigfpe arithmetic exception:

    corrupt file

    What file exactly is that? Please post whole error message.

  • @jsulm ah, it's myvideocapture.cpp, main and mainwindow.cpp (according to the debugger). but now i face yet another challenge, which has been mention above, any idea?

  • Lifetime Qt Champion

    @NoobDude12343 Do you mean the issue @Christian-Ehrlicher replied to?

  • @NoobDude12343 said in qt sigfpe arithmetic exception:

    lnk1107 invalid or corrupt file

    It's a linker issue. It looks like you're messing up with some library, not using the proper one (maybe some wrong file from OpenCV?). See for instance this SO question.

  • @jsulm yeah

Log in to reply