Results 1 to 3 of 3

Thread: Cannot call OpenCV 2.0 functions inside Qt slots

  1. #1
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Cannot call OpenCV 2.0 functions inside Qt slots

    Hi all,

    I have a Qt (4.6 mingw) application that uses OpenCV (2.0) for image processing.

    Everything was working fine with OpenCV 1.0 but when I upgraded to
    OpenCV 2.0 it started crashing.
    I noticed that it only crashes whenever OpenCV functions are called
    inside Qt slots.

    For instance, the following slot:

    Qt Code:
    1. void TestClass::on_testButton_clicked() {
    2. IplImage* src = cvLoadImage("test.jpg");
    3. IplImage* dst = cvCreateImage(cvGetSize(src), src->depth, src->nChannels);
    4. cvThreshold(src, dst, 100, 255, CV_THRESH_BINARY);
    5. }
    To copy to clipboard, switch view to plain text mode 

    crashes when testButton is clicked.

    However:
    If I call the same cvThreshold function in any other place such as main or the Widget's constructor, it works.
    If f I put the same code in a separate function and call that function with QtConcurrent::run() inside the same slot, it works.
    If I use OpenCV 1.0, it works.

    Why this behaviour? Are there any restrictions about the operations that can be done inside Qt slots?

    Thanks in advance.
    Last edited by Asfer; 19th February 2010 at 11:48.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Cannot call OpenCV 2.0 functions inside Qt slots

    In such cases it is good to run this in a debugger, and step through until the crashing line.
    Then you know exactly which line is crashing.
    Next, you have to examine all the parameters in the call that is crashing.
    If you have a debug build of your OpenCV you can drill with the debugger in to it, if the crash is in the lib, and not your code.
    Knowing exactly which line crashed helps a lot to solve the problem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cannot call OpenCV 2.0 functions inside Qt slots

    Hi, thanks for your reply.

    Problem solved, I was using OpenCV's precompiled libraries, which were created with a different version of mingw.
    I compiled the library with cmake+mingw and using the generated libraries solved the problem.

Similar Threads

  1. Replies: 4
    Last Post: 16th February 2009, 07:10
  2. Replies: 3
    Last Post: 4th March 2008, 08:35
  3. trying to call Xlib inside qt app
    By phixx in forum Qt Programming
    Replies: 4
    Last Post: 12th February 2008, 20:28
  4. Replies: 1
    Last Post: 6th April 2006, 12:24
  5. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 21:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.