Qt weird no such file or directory behavior



  • 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.


  • Qt Champions 2017

    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?



  • 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.


  • Qt Champions 2017

    @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 :)



  • 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 ♥


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.