Results 1 to 4 of 4

Thread: Using OpenCV with QT creator

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Mar 2006
    Location
    Chicago
    Posts
    8
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using OpenCV with QT creator [SOLVED]

    I have solved my issue. Apparently when you install Qt through the .bin file they have on the site it does not change your path, which cmake relies on but QtCreator does not. To do this, edit your bash.bashrc file with superuser permission and add the following lines to the end of the file:

    Qt Code:
    1. export QTDIR=/opt/qtsdk-2010.04/qt
    2. export PATH=$QTDIR/bin:$PATH
    3. export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
    To copy to clipboard, switch view to plain text mode 

    If you use gnome, use: sudo gedit /etc/bash.bashrc, for KDE I think you would use: sudo kate /etc/bash.bashrc
    Also you may have to modify line 1 to match your own QT installation directory.

    Modify the following file for your CMakeLists.txt project:

    Qt Code:
    1. # You must set the minimum version for CMake
    2. CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
    3.  
    4. # This is the name of your project:
    5. PROJECT(ObjDetect_proj)
    6.  
    7. SET(CMAKE_BUILD_TYPE Release)
    8. SET(CMAKE_CXX_FLAGS "-Wall")
    9.  
    10. # Use this for additional packages you need support for. In this case, I am using OpenCV.
    11. # Consult CMake documentation to see which packages are supported and what the command is.
    12. FIND_PACKAGE( OpenCV REQUIRED )
    13.  
    14. # QT4 Handling
    15. FIND_PACKAGE(Qt4 REQUIRED)
    16. INCLUDE_DIRECTORIES( ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
    17.  
    18. INCLUDE(${QT_USE_FILE})
    19.  
    20. # Change these to all your header files
    21. SET( HWQ_Qt4_SRC
    22. src/MainWindow.h
    23. src/ObjDetect.h
    24. )
    25. # Change this to all your .ui designer files
    26. SET( HWQ_Qt4_UI
    27. src/MainWindow.ui
    28. )
    29. # Add resource files if you have them.
    30. SET( HWQ_Qt4_RES
    31. )
    32.  
    33. # This runs the QT MOC
    34. QT4_WRAP_CPP(HWQ_MOC_CPP ${HWQ_Qt4_SRC})
    35. # This creates your ui_whatever.h files
    36. QT4_WRAP_UI(HWQ_UI_CPP ${HWQ_Qt4_UI})
    37. QT4_ADD_RESOURCES(HWQ_RES_H ${HWQ_Qt4_RES})
    38.  
    39. INCLUDE_DIRECTORIES( . )
    40.  
    41. # Put your cpp files here
    42. SET( HWQ_SRC
    43. src/main.cpp
    44. src/MainWindow.cpp
    45. src/ObjDetect.cpp
    46. ${HWQ_MOC_CPP}
    47. ${HWQ_UI_CPP}
    48. ${HWQ_RES_H}
    49. )
    50.  
    51. SET( HWQ_LIB
    52. ${QT_LIBRARIES}
    53. )
    54.  
    55. ADD_EXECUTABLE(ObjDetect ${HWQ_SRC} )
    56. TARGET_LINK_LIBRARIES(ObjDetect ${HWQ_LIB} ${OpenCV_LIBS} )
    57.  
    58. # I think this line only gets called when you run 'make install'
    59. INSTALL_TARGETS( /bin Objdetect)
    To copy to clipboard, switch view to plain text mode 

    Now I don't know why exactly, but when you run CMake from Qt Creator, it screws up. You have to go to the command line first and run
    Qt Code:
    1. cmake .
    To copy to clipboard, switch view to plain text mode 
    After you run this initially, you can open the CMakeLists.txt file with QtCreator and it will open your whole project and build and link correctly.

    I hope this helps some other poor sucker trying to figure this stuff out.

    -Greg

  2. The following user says thank you to gmiller39 for this useful post:

    fezvez (8th July 2010)

Similar Threads

  1. OpenCV + QT4
    By thereisnoknife in forum Qt Programming
    Replies: 6
    Last Post: 8th March 2013, 05:19
  2. opencv-qt-mac
    By ireneluis in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2010, 15:24
  3. Qt and OpenCV
    By malorie in forum Newbie
    Replies: 2
    Last Post: 7th March 2010, 14:57
  4. OpenCv & Qt4
    By switch in forum Qt Programming
    Replies: 0
    Last Post: 4th August 2009, 15:12
  5. OpenCv + Qt
    By Janderson Borges in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2008, 13:01

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
  •  
Qt is a trademark of The Qt Company.