Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt weird no such file or directory behavior
Forum Updated to NodeBB v4.3 + New Features

Qt weird no such file or directory behavior

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yugosonegi
    wrote on last edited by yugosonegi
    #1

    I have a project with the QT += core network on Qt Creator I can include the #include <QLocalServer> normally, I can even right click on it to see the source and so on, but when trying to compile it gives me an error saying that the file could not be found.

    What is happening?

    The Qt I'm using is 5.10 and Qt Creator 4.5 with MSVC 2015 64bit and it's a new installation, no modifications at all.

    The complete pro file:

    include($$PWD/../defines.pri)
    
    QT      += core network
    TARGET   = libtuts
    TEMPLATE = lib
    DEFINES += TUTS_LIBRARY
    HEADERS += core/libtuts_global.hpp \
               core/safeguard.hpp
    SOURCES += core/safeguard.cpp
    

    update:

    I only gives me the error if I try to include in the core/safeguard.hpp but not in the core/safeguard.cpp. WEIRD.

    aha_1980A 1 Reply Last reply
    0
    • Y yugosonegi

      I have a project with the QT += core network on Qt Creator I can include the #include <QLocalServer> normally, I can even right click on it to see the source and so on, but when trying to compile it gives me an error saying that the file could not be found.

      What is happening?

      The Qt I'm using is 5.10 and Qt Creator 4.5 with MSVC 2015 64bit and it's a new installation, no modifications at all.

      The complete pro file:

      include($$PWD/../defines.pri)
      
      QT      += core network
      TARGET   = libtuts
      TEMPLATE = lib
      DEFINES += TUTS_LIBRARY
      HEADERS += core/libtuts_global.hpp \
                 core/safeguard.hpp
      SOURCES += core/safeguard.cpp
      

      update:

      I only gives me the error if I try to include in the core/safeguard.hpp but not in the core/safeguard.cpp. WEIRD.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      Hi @yugosonegi,

      can you please post the exact error message? (copy it from Creators compile output)

      May it be that the safeguard.hpp is included from other parts of your program that don't have the QT += network set?

      Qt has to stay free or it will die.

      1 Reply Last reply
      3
      • Y Offline
        Y Offline
        yugosonegi
        wrote on last edited by
        #3

        You are right, as it's a library and I'm using somewhere else I needed to put network on the other pro file as well.

        The weird part about that is that the compiler don't tell that, only shows that the file is missing and that is it.

        aha_1980A 1 Reply Last reply
        0
        • Y yugosonegi

          You are right, as it's a library and I'm using somewhere else I needed to put network on the other pro file as well.

          The weird part about that is that the compiler don't tell that, only shows that the file is missing and that is it.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @yugosonegi said in Qt weird no such file or directory behavior:

          You are right, as it's a library and I'm using somewhere else I needed to put network on the other pro file as well.

          I think a library should be self-contained, i.e. a library user should not have to add extra include or link statements on his side.

          Maybe you can separate your libary in private and public header files. Or maybe you use a forward declaration in your header file and only #include <QLocalServer> in the CPP file:

          // Header file
          
          // forward declaration
          QT_BEGIN_NAMESPACE
          class QLocalServer;
          QT_END_NAMESPACE
          
          class SafeGuard {
          // ...
          private:
            // only pointer is used here, so forward declaration is enough
            QLocalServer *m_server = nullptr; 
          }
          

          The QT_BEGIN/END_NAMESPACE may not be necessary for you at most times, but they are if you build Qt yourself in a namespace, therefore I added them: https://wiki.qt.io/Qt_In_Namespace

          The weird part about that is that the compiler don't tell that, only shows that the file is missing and that is it.

          Yes, that's the life of a C++ programmer :)

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yugosonegi
            wrote on last edited by
            #5

            I'm not using the LocalServer as a pointer so that is why I needed the include in the header.
            I'm not going to change to pointer as I think it's not needed so I'm going to stick with the insertion of network where it's needed.

            Thank you very much ♥

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved