Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qt sigfpe arithmetic exception

qt sigfpe arithmetic exception

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 674 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NoobDude12343
    wrote on last edited by
    #1

    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:
    .pro:

    #-------------------------------------------------
    #
    # 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.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # 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 \
            myvideocapture.cpp
    
    HEADERS += \
            mainwindow.h \
            myvideocapture.h
    
    FORMS += \
            mainwindow.ui
    
    # 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
    

    myvideocapture.cpp:

    #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);
        #else
                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,
                             static_cast<int>(inMat.step),
                             QImage::Format_Indexed8 );
    
                image.setColorTable(sColorTable );
        #endif
                return image;
            }
            default:
            {
                qWarning()<< "ASM::cvMatToQImage()- cv::Mat image type not handled in switch:" << inMat.type();
                break;
            }
        }
        return QImage();
    }
    
    QPixmap MyVideoCapture::cvMatToQPixmap(const cv::Mat &inMat)
    {
        return QPixmap::fromImage(cvMatToQImage(inMat));
    }
    

    mainwindow.cpp:

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

    main.cpp:

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        a.setStyle("fusion");
        MainWindow w;
    ////////////////////this line///////////////////////////
        w.show();
        return a.exec();
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • N Offline
          N Offline
          NoobDude12343
          wrote on last edited by
          #4

          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?

          jsulmJ Pablo J. RoginaP 2 Replies Last reply
          0
          • N NoobDude12343

            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?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @NoobDude12343 said in qt sigfpe arithmetic exception:

            corrupt file

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

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            N 1 Reply Last reply
            0
            • jsulmJ jsulm

              @NoobDude12343 said in qt sigfpe arithmetic exception:

              corrupt file

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

              N Offline
              N Offline
              NoobDude12343
              wrote on last edited by
              #6

              @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?

              jsulmJ 1 Reply Last reply
              0
              • N NoobDude12343

                @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?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

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

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                N 1 Reply Last reply
                0
                • N NoobDude12343

                  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?

                  Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #8

                  @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.

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

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

                    N Offline
                    N Offline
                    NoobDude12343
                    wrote on last edited by
                    #9

                    @jsulm yeah

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved