Results 1 to 2 of 2

Thread: Opencv + Qt first basic application not working

  1. #1
    Join Date
    Oct 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Opencv + Qt first basic application not working

    So I installed openCV and wanted to make a very basic program with Qt, when I compiled and ran the program it would return a command line window with the message "press <return> to close" and the Qt output panel printed "...exe exited with code 0" ??

    I know that it means there were no errors and everything was successful but why didnt it execute the actual code which is suppose to get the cameras video and display it in a new window.

    Btw here is my code:

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <opencv2/core/core.hpp>
    3. #include <opencv2/highgui/highgui.hpp>
    4.  
    5. #include <QtCore>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QCoreApplication a(argc, argv);
    10.  
    11. cv::VideoCapture cam = cv::VideoCapture(0);
    12. cv::Mat frame;
    13. cv::namedWindow ("Demo", CV_WINDOW_AUTOSIZE);
    14.  
    15. while (1) {
    16. cam >> frame;
    17. imshow ("Demo", frame);
    18. }
    19.  
    20. cam.release();
    21. return 0;
    22.  
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

    And here is my .pro file if it matters:

    Qt Code:
    1. QT += core
    2.  
    3. QT -= gui
    4.  
    5. TARGET = WebCam
    6. CONFIG += console
    7. CONFIG -= app_bundle
    8.  
    9. TEMPLATE = app
    10.  
    11.  
    12. SOURCES += main.cpp
    13.  
    14. INCLUDEPATH += "C:\openCV24\opencv_bin\install\include"
    15.  
    16. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_calib3d240.dll.a"
    17. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_contrib240.dll.a"
    18. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_core240.dll.a"
    19. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_features2d240.dll.a"
    20. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_flann240.dll.a"
    21. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_gpu240.dll.a"
    22. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_highgui240.dll.a"
    23. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_imgproc240.dll.a"
    24. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_legacy240.dll.a"
    25. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_ml240.dll.a"
    26. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_nonfree240.dll.a"
    27. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_objdetect240.dll.a"
    28. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_photo240.dll.a"
    29. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_stitching240.dll.a"
    30. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_video240.dll.a"
    31. LIBS += "C:\openCV24\opencv\build\x86\mingw\lib\libopencv_videostab240.dll.a"
    To copy to clipboard, switch view to plain text mode 

    Thanks appreciate any help to get me up and running

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Opencv + Qt first basic application not working

    If your program is terminating on its own then the program is never reaching line 15. If it reached this line it would never return. The only exit before this point is an abnormal termination.

    Assuming your OpenCV has been compiled with Qt support (otherwise this question has nothing to do with Qt) the debug output probably contains a message like:
    Qt Code:
    1. QWidget: Cannot create a QWidget when no GUI is being used
    2. Aborted
    To copy to clipboard, switch view to plain text mode 

    You need to use QApplication and link the Qt gui library. Then you can worry about making the program do what you expect.

Similar Threads

  1. Need Help in Distributing a Basic QT Application
    By LinuxProgrammer007 in forum Installation and Deployment
    Replies: 0
    Last Post: 3rd September 2012, 22:17
  2. OpenCV cvSmooth not working in Qt, but OK in Visual C++ 2008
    By aoikyou in forum Installation and Deployment
    Replies: 3
    Last Post: 31st March 2012, 04:21
  3. Replies: 0
    Last Post: 3rd March 2011, 17:01
  4. Basic Qt Application Design
    By bmarkev in forum Newbie
    Replies: 1
    Last Post: 9th September 2010, 03:38
  5. Trying to get basic signals example working
    By mrstephengross in forum Qt Programming
    Replies: 5
    Last Post: 27th February 2007, 19:58

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.