【问题标题】:QT moc class can not find the original file, despite it being in correct directoryQT moc 类找不到原始文件,尽管它位于正确的目录中
【发布时间】:2022-01-14 17:18:04
【问题描述】:

我正在尝试构建 qt 项目,但我不断收到关于 moc 对象 moc_SerialPortManager.cpp 中没有现有标头的错误。我使用 bash 移动到该目录,并使用 cd cmd 和用模拟对象编写的路径,它指向正确的目录。有没有人知道如何解决它?在这一点上,这是一个相当大的项目,所以请告诉我我可以发布什么来让你更容易? 我在 git https://github.com/Orpiczy/AcornScanner/compare/fronAndBackJoin 上都有,如果你想查看的话

我正在为 c++ 和 Qt 6.2.0 使用 Mingw 编译器 8.1.0 64 位,我正在使用 windows10

moc_SerialPortManager.cpp

#include <memory>
#include "../../../../../../source/controllers/LowLevelFunctionality/DeviceController/ProfilometerManager/SerialPortManager.hpp"
#include <QtCore/qbytearray.h> ...

日志 E:\Dokumenty\AiR_rok_4\S7\EngineeringThesis\AcornScanner\cm\cm-lib\build\windows\gcc\x64\debug.moc\moc_SerialPortManager.cpp:10:错误:../../../.. /../../source/controllers/LowLevelFunctionality/DeviceController/ProfilometerManager/SerialPortManager.hpp:没有这样的文件或目录 ........\AcornScanner\cm\cm-lib\build\windows\gcc\x64\debug.moc\moc_SerialPortManager.cpp:10:10:致命错误:../../../。 ./../../source/controllers/LowLevelFunctionality/DeviceController/ProfilometerManager/SerialPortManager.hpp:没有这样的文件或目录 #include "../../../../../../source/controllers/LowLevelFunctionality/DeviceController/ProfilometerManager/SerialPortManager.hpp" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~

【问题讨论】:

    标签: c++ qt compiler-errors path mocking


    【解决方案1】:

    请注意,存储库的布局与本地文件系统不同:

    .../debug/.moc/
    

    对比

    .../debug.moc/
    

    因此,相对路径上升一级太多,导致路径不存在。

    将自动生成的文件(即 moc 文件)置于版本控制之下通常被认为是不好的做法。我假设如果你删除整个 build 目录并重新构建你会没事的。

    【讨论】:

    • 感谢您的建议,这是我第一次真正开始使用 git,这就是我跳过 .gitignore 的原因。关于问题 -> 我已将我的项目从一个文件夹移动到另一个文件夹,并且影子构建一直在旧位置编译,这就是它不起作用的原因。我只是在项目设置中更改了它:)
    • 我很高兴听到它现在有效。如果答案解决了您的问题,您可以考虑将其设置为“已接受”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多