title: Qt - main() function of referenced project covering main() of the actual project
body: <p>I am making a unit tests Qt project in Qt Creator that references files from the project I want to test. Now, whether I reference classes I want to test through a .pri file or by adding relevant files directly to the SOURCES and HEADERS variables of the unit tests project (and .pri file really seems to do the same anyway, it just contains SOURCES and HEADERS entries), adding files from the main project seems to overwrite the main.cpp in the unit tests project.</p>
  
  <p>What I mean is that when I build and run the uni tests executable, the <code>main()</code> function of the original project runs! If I rename either the main.cpp in the original project, or the main.cpp in the unit tests project (which changes its .pro file), then things go smoothly. Well, I can live with such solution, but it makes a bit uncomfortable, because  one day in the future I might accidentally use same names for some files in those two projects and who knows, maybe get errors that will be a nightmare to track down. Beside I'm simply curious as to what's the cause of such behaviour.</p>
  
  <p>Of course the .pri file only includes class headers and cpp files, not the main.cpp of the original application, e.g. in my case:</p>
  
  <pre><code>HEADERS += \
      ../Project/fooclass.h
  
  SOURCES += \
      ../Project/fooclass.cpp
  </code></pre>
  
  <p>Also both projects are in directories next to each other, not nested.</p>
  
  <p>Edit: <a href="https://stackoverflow.com/a/9782631/760239">Frank Osterfeld</a> asked to see my test's pro file, so here it is:</p>
  
  <p>Test's pro file:</p>
  
  <pre><code>QT       += core
  QT       -= gui
  QT += testlib
  
  TARGET = Tests
  CONFIG   += console
  CONFIG   -= app_bundle
  
  TEMPLATE = app
  
  SOURCES += \
      test_class.cpp \
      main_unit_tests.cpp
  
  HEADERS += \
      AutoTest.h \
      test_class.h \
  
  include(trial.pri)
  </code></pre>
  
  <p>Trial.pri contains files from main project I want to test. main_unit_tests.cpp (renamed from original main.cpp as an ad-hoc solution) contains:</p>
  
  <pre><code>#include &lt;QtCore/QCoreApplication&gt;
  #include "AutoTest.h"
  
  TEST_MAIN
  </code></pre>
  
  <p><code>TEST_MAIN</code> is defined in AutoTest.h as</p>
  
  <pre><code>#define TEST_MAIN \
    int main(int argc, char *argv[]) \
    { \
      return AutoTest::run(argc, argv); \
  }
  </code></pre>
  
  <p>Visit this <a href="http://qtcreator.blogspot.ca/2010/04/sample-multiple-unit-test-project.html" rel="nofollow noreferrer">page</a> for the description of what does AutoTest.h do. In short it makes running multiple unit test with Qt framework a bit less hassle.</p>
  
  <hr>
  
  <p>Edit:
  pro. file of the main project (i.e. one containing classes I want to test) is:</p>
  
  <pre><code>QT       += core
  QT       -= gui
  
  TARGET = Project
  CONFIG   += console
  CONFIG   -= app_bundle
  
  TEMPLATE = app
  
  SOURCES += main.cpp \
      fooclass.cpp
  
  HEADERS += \
      fooclass.h
  </code></pre>
  
  <p>And it lies on the path: ...\Unit_Test\Project
  Whereas the unit tests project lies on the path: ...\Unit_Test\Tests
  Right now things work fine as files defining <code>main()</code> are different in both projects. As soon as I rename them so they're the same, the unit tests projects excutes main function of the original project.</p>