Question

I have a command line openCV program that I wrote in Xcode that opens two XML files, analyses and then compares them. However, I'm now trying to put that program into a GUI using QtCreator to make it easier to understand the output.

The problem is, Qt doesn't seem to like cv::FileStorage. The program compiles fine, but when I actually try to execute the OpenCV part, it crashes, giving this error:

OpenCV Error: Null pointer (NULL or empty buffer) in cvOpenFileStorage, file /tmp/OpenCV-2.4.3/modules/core/src/persistence.cpp, line 2702 Qt has caught an exception thrown from an event handler. Throwing exceptions from an event handler is not supported in Qt. You must reimplement QApplication::notify() and catch all exceptions there.

The program has unexpectedly finished.

Does anyone know why Qt doesn't seem to like running this program? Or if there's a way that I can cleanly integrate the OpenCV program into the Qt one?

N.B. This is what the Qt GUI looks like:

enter image description here

The user selects the two XML files with the relevant buttons. The paths to these files are then stored and displayed in the boxes next to the buttons. I then convert the QStrings to std::strings using the following:

std::string file1path = file1Name.toUtf8().constData();
std::string file2path = file2Name.toUtf8().constData();

file1path and file2path are then passed to the cv::FileStorage commands as follows:

//Create File Storage
FileStorage storage1;
storage1.open(file1path, FileStorage::READ);

FileStorage storage2;
storage2.open(file2path, FileStorage::READ);
Was it helpful?

Solution

It's not Qt specifically.
OpenCV is throwing an error in your use of fileStorage, either file doens't exist, isn't readable, or you are trying to read the wrong types.

Qt gives you that error because the exception has reached it's general error handler for an unchecked exception rather than openCv, which would print a more useful error.

You can add a global excpetion handler to a Qt app by adding a method to QApplication

bool QApplication::notify ( QObject * receiver, QEvent * event )
    {
      try{
        return QApplication::notify( received, event );
      }
      catch ( const std::exception &e )
      {
        QApplication::postEvent( this, new MyEvent( e.what() );
      }
      catch ( ... )
      {

      }

See also http://qt-project.org/doc/qt-4.8/exceptionsafety.html

OTHER TIPS

Try replace "" for "/" if you use it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top