title: CMake, forward declarations, signals and 'No such file or directory'
body: <p>I am trying to develop a user interface in Qt, which is  connected to some logic. I have successfully sent signals from the logic to the user interface, but now I require to do it the other way around too. I face a <code>QMainWindow: No such file or directory</code> error when I try to compile the project.</p>
  
  <p>I know for sure that it is a problem of including the classes to each other, and therefore I have tried to perform some forward declaration. But I have been unable to do it properly. I have tried many ways but I don't seem to achieve it.</p>
  
  <p>I tried to create an empty class in the client's header file, <code>class QTGUI;</code> and include the <code>qtgui.hpp</code> only in <code>client.cpp</code>, and the same analogous thing with <code>QTGUI</code> files. What am I doing wrong?</p>
  
  <p>Thank you very much in advance.</p>
  
  <hr>
  
  <h2>Updated CMakeLists and source codes. The original stuff is below.</h2>
  
  <p><strong>Main CMakeLists</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  project(backendCode)
  
  find_package(Boost COMPONENTS system)
  include_directories(${Boost_INCLUDE_DIR})
  
  SET(THREADLIBS "-lpthread -lboost_thread")
  
  SET(FSLIBS "-lboost_filesystem -lboost_system")
  
  add_subdirectory(gui)
  add_subdirectory(server)
  </code></pre>
  
  <p><strong>GUI CMakeLists</strong>: In comparison with the original code, I included the client stuff here.</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
  project(QtGui)
  
  set(CMAKE_AUTOMOC ON)
  set(CMAKE_AUTOUIC ON)
  set(CMAKE_INCLUDE_CURRENT_DIR ON)
  
  find_package(Qt5Widgets REQUIRED)
  find_package(Qt5Network REQUIRED)
  
  include_directories(${Qt5Widgets_INCLUDE_DIRS})
  add_definitions(${QT_DEFINITIONS})
  
  
  add_executable(main main.cpp qtgui.cpp ../common/inotify.cpp 
  ../client/client.cpp ../common/message.cpp)
  target_link_libraries(main Qt5::Widgets Qt5::Network ${Boost_LIBRARIES} 
  ${THREADLIBS})
  </code></pre>
  
  <p><strong>QTGUI.h</strong></p>
  
  <pre><code>#ifndef QTGUI_H
  #define QTGUI_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QFileSystemWatcher&gt;
  
  #include &lt;boost/enable_shared_from_this.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/signals2.hpp&gt;
  
  #include "../common/inotify.hpp"
  
  class Client;
  
  namespace Ui {
  class QTGUI;
  }
  
  class QTGUI : public QMainWindow
  {
      Q_OBJECT
  
  public:
  ...
  private:
      boost::shared_ptr&lt;Client&gt; client_;
      Ui::QTGUI* ui;
  };
  #endif // QTGUI_H
  </code></pre>
  
  <p><strong>QTGUI.cpp</strong></p>
  
  <pre><code>#include "QTGUI.h"
  #include "ui_qtgui.h"
  
  #include &lt;iostream&gt;
  
  #include &lt;QHostAddress&gt;
  #include &lt;QRegExp&gt;
  #include &lt;QIntValidator&gt;
  #include &lt;QFileDialog&gt;
  
  #include &lt;unistd.h&gt;
  #include &lt;pwd.h&gt;
  #include &lt;sys/types.h&gt;
  
  #include "../client/client.hpp"
  ...
  </code></pre>
  
  <p><strong>CLIENT.HPP</strong></p>
  
  <pre><code>#ifndef CLIENT_HPP
  #define CLIENT_HPP
  
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/enable_shared_from_this.hpp&gt;
  #include &lt;boost/scoped_ptr.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  
  #include &lt;boost/signals2.hpp&gt;
  
  #include "../common/message.hpp"
  
  class QTGUI;
  
  class Client : public boost::enable_shared_from_this&lt;Client&gt;
  {
      {
          public:
          ...
          private:
          boost::shared_ptr&lt;QTGUI&gt; ui_;
          };
  
          #endif // CLIENT_H
  </code></pre>
  
  <p><strong>CLIENT.CPP</strong></p>
  
  <pre><code>#include &lt;boost/bind.hpp&gt;
  
  #include &lt;cstdio&gt; /* sprintf */
  
  #include "client.hpp"
  #include "../gui/QTGUI.h"
  
  #include &lt;unistd.h&gt;
  
  Client::Client():
  ...
  </code></pre>
  
  <hr>
  
  <h2>Original code</h2>
  
  <p>I have the following in my <strong>main</strong> CMakeLists:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  project(backendCode)
  
  find_package(Boost COMPONENTS system)
  include_directories(${Boost_INCLUDE_DIR})
  
  SET(BOOSTHREAD "-lpthread -lboost_thread")
  
  SET(FSLIBS "-lboost_filesystem -lboost_system")
  
  add_subdirectory(gui)
  add_subdirectory(client)
  add_subdirectory(server)
  </code></pre>
  
  <p>The following, in the <strong>gui</strong> CMakeLists:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
  project(QtGUI)
  
  set(CMAKE_AUTOMOC ON)
  set(CMAKE_AUTOUIC ON)
  set(CMAKE_INCLUDE_CURRENT_DIR ON)
  
  find_package(Qt5Widgets REQUIRED)
  find_package(Qt5Network REQUIRED)
  
  include_directories(${Qt5Widgets_INCLUDE_DIRS})
  add_definitions(${QT_DEFINITIONS})
  
  
  add_executable(main main.cpp qtgui.cpp ../common/inotify.cpp)
  target_link_libraries(main client Qt5::Widgets Qt5::Network ${Boost_LIBRARIES} 
  ${BOOSTHREAD})
  </code></pre>
  
  <p>In the qtgui.h header file I have the following code:</p>
  
  <pre><code>#ifndef QTGUI_H
  #define QTGUI_H
  
  #include &lt;QMainWindow&gt;
  
  #include &lt;boost/enable_shared_from_this.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/signals2.hpp&gt;
  
  #include "../client/client.hpp"
  
  namespace Ui {
  class QTGUI;
  }
  class QTGUI    : public QMainWindow
  {
      Q_OBJECT
  ...
      private:
          boost::shared_ptr&lt;Client&gt; client_;
  };
  #endif
  </code></pre>
  
  <p>Finally, in the client.hpp file I have the following code:</p>
  
  <pre><code>#ifndef CLIENT_HPP
  #define CLIENT_HPP
  
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/enable_shared_from_this.hpp&gt;
  #include &lt;boost/scoped_ptr.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  
  #include &lt;boost/signals2.hpp&gt;
  
  #include "../gui/qtgui.h"
  
  class QTGUI;
  
  class Client : public boost::enable_shared_from_this&lt;Client&gt;
  {
      ...
  private:
      boost::shared_ptr&lt;QTGUI&gt; ui_;
  };
  #endif
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong> Added the <code>namespace</code> thing into the <code>qtgui.h</code>.</p>