QMouseEvent no such file or directory when header is included in another file



  • Hello,
    I have a header StdAfx.h file with a lot of include. Among them, I have

    #include <QMouseEvent>
    #include <QPainter>
    #include <QSerialPort>

    And everything works fine. However, if I include this StdAfx.h into another header LtUtil.h that just defines several functions, I have several compilation error
    StdAfx.h:41: error: C1083: Cannot open include file: 'QMouseEvent': No such file or directory

    If I add QtGui/QMouseEvent it works and stop on the next include.

    Why do including my header prevents me from using the short #include <QMouseEvent> ?


  • Qt Champions 2016

    Hmm
    Maybe path are wrong when seen from StdAfx.h
    Is that not the normal visual studio common include?

    Also depends on the project settings, include paths etc.

    It should not prevent the use of
    #include <QMouseEvent>
    in any case.

    Are you using Qt4?



  • Im using qt 5.7.1 on Linux (Fedora) and Qt 5.7.0 on Windows 7 (same behavior)

    StdAfx is indeed usually something created by Visual Studio, but the person that created the code structure is long gone, so I dont really know why evertyhing is in a separate header and in a separate folder.

    edit : if I include StdAfx in my cpp instead of my header, everything is fine, so I guess I'll move the inlines function to the .cpp aswell.
    But I still dont understand why it messes up with Qt include


  • Moderators

    stdafx.h is usually intended to be a precompiled header, so it should be included as first thing in the .cpp files, not in headers.
    As to why your problem happens - this type of error usually means that the header you're including stdafx.h in or the file itself is not included in the project or is included in a project that doesn't use that Qt library (i.e. doesn't have that module in the .pro file or the include paths are not set correctly in the visual studio project, whichever you're using).



  • Thanks for the clarification about the precompiled header.
    And I think your explanation about the issue correspond to my case.

    Now I need to think about how to include properly the header I need to declare my templates, but thats another story.


Log in to reply
 

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