title: Opencv sample in Qt crashes immediately with the error 'The program has unexpectedly finished'
body: <p>I tried to create a simple Opencv application in Qt and upon running, the whole application is crashed. If I comment out the opencv related codes from the project, the project runs just fine.   </p>
  
  <p>What I did:</p>
  
  <pre><code>Downloaded the Qt 5.5.0 VS2013 64bit version   
  Downloaded the OpenCV 3.0   
  Downloaded the Cmake 3.3.2  
  </code></pre>
  
  <p>There were already prebuilt binaries in when I extracted the Opencv package, But all tutorials on the net wanted me to recompile the source codes so did I. The package contains:</p>
  
  <pre><code>build
  sources
  </code></pre>
  
  <p>created a new folder named <code>mymade</code> to hold the binaries next to the other two directories. So it now looks like this: </p>
  
  <pre><code> build
   mymade
   sources
  </code></pre>
  
  <p>Steps:</p>
  
  <ul>
  <li>Fired up <code>CMake</code>, specified the source folder from the extracted files 
  and specified <code>mymade</code> as the output for binaries.   </li>
  <li>checked all options that had a <code>opencv</code> in their names, plus Qt! and configured it and subsequently generated the files.   </li>
  </ul>
  
  <p>This is the resulting contents:</p>
  
  <p><a href="https://i.stack.imgur.com/QTfoG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QTfoG.jpg" alt="enter image description here"></a></p>
  
  <p>So all is done and I now need to build the binaries. I opened <code>OpenCV.sln</code> and compiled the release and debug binaries. The dlls are placed inside <code>bin</code> directory, and the lib files are placed inside <code>lib</code> folder.</p>
  
  <p>Now it's the time to configure the Qt projects <code>.pro</code> file, so I used the header files from build directory, and for libs I used the lib folder from <code>mymade</code> folder. This is the first configuration that I came up with, which compiles without any linker issues, but crashes just immediately.     </p>
  
  <p>The initial changes in project file : </p>
  
  <pre><code>#-------------------------------------------------
  #
  # Project created by QtCreator 2015-10-06T14:04:20
  #
  #-------------------------------------------------
  
  QT       += core gui
  
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  
  TARGET = OpenCVTest
  TEMPLATE = app
  
  SOURCES += main.cpp\
          mainwindow.cpp
  
  HEADERS  += mainwindow.h
  
  
  INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib
  
  FORMS    += mainwindow.ui
  </code></pre>
  
  <p>Doing this in project file as it was suggested by answers like <a href="https://stackoverflow.com/questions/18151412/opencv-with-qt-the-program-has-unexpectedly-finished">this</a> didn't do any good either:</p>
  
  <pre><code>#-------------------------------------------------
  #
  # Project created by QtCreator 2015-10-06T14:04:20
  #
  #-------------------------------------------------
  
  QT       += core gui
  
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  
  TARGET = OpenCVTest
  TEMPLATE = app
  
  SOURCES += main.cpp\
          mainwindow.cpp
  
  HEADERS  += mainwindow.h
  
  
  INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
  
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
  LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib
  
  FORMS    += mainwindow.ui
  </code></pre>
  
  <p>This fails as well:</p>
  
  <pre><code>#-------------------------------------------------
  #
  # Project created by QtCreator 2015-10-06T14:04:20
  #
  #-------------------------------------------------
  
  QT       += core gui
  
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  
  TARGET = OpenCVTest
  TEMPLATE = app
  
  SOURCES += main.cpp\
          mainwindow.cpp
  
  HEADERS  += mainwindow.h
  
  
  INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
  
  LIBS +=-L"L://Apps_Installation_Folder//opencv//mymade//lib//Release"
  LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300
  
  
  FORMS    += mainwindow.ui
  </code></pre>
  
  <p>So what is the problem here?</p>
  
  <h2>Update</h2>
  
  <p>As it was pointed out by @Miki, Qt couldn't find the opencv dlls (the configs above were OK but), And to solve this problem, one only needs to add the directory containing dlls to the PATH variable, there you are good to go and everything should be fine now.</p>