Qt当我尝试包括头文件时,没有这样的文件或词典

QT No such file or dictionary when I try to include a header file(Qt当我尝试包括头文件时,没有这样的文件或词典)
本文介绍了Qt当我尝试包括头文件时,没有这样的文件或词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Qt中非常常见的问题。包括头文件,然后出现错误。

No such file or directory

如何重现问题:

  1. 首先我使用的是CAN Bus Open SAE J1939库

  2. 然后,我像这样包括源和标头。

    SOURCES += 
     Communication/Database/databasehandling.cpp 
     Tool/Json/jsonhandling.cpp 
     main.cpp 
     Window/Main/mainwindow.cpp 
     Communication/USB/usb.cpp 
     Tool/CAN/Hardware/CAN_Network/CAN_Network.c 
     Tool/CAN/Hardware/Memory/FLASH_EEPROM_RAM_Memory.c 
     Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Auxiliary_Valve_Command.c 
     Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Auxiliary_Valve_Estimated_Flow.c 
     Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Auxiliary_Valve_Measured_Position.c 
     Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/General_Purpose_Valve_Command.c 
     Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/General_Purpose_Valve_Estimated_Flow.c 
     Tool/CAN/Open_SAE_J1939/Listen_For_Messages.c 
     Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Acknowledgement.c 
     Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Request.c 
     Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Protocol_Connection_Management.c 
     Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Protocol_Data_Transfer.c 
     Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Request_Component_Identification.c 
     Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Request_ECU_Identification.c 
     Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Request_Software_Identification.c 
     Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM1.c 
     Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM2.c 
     Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM3.c 
     Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM14.c 
     Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM15.c 
     Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM16.c 
     Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Address_Claimed.c 
     Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Address_Delete.c 
     Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Address_Not_Claimed.c 
     Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Commanded_Address.c
    
    HEADERS += 
     Communication/Database/databasehandling.h 
     Tool/Json/jsonhandling.h 
     Window/Main/mainwindow.h 
     Communication/USB/usb.h 
     Tool/CAN/Hardware/CAN_Network/CAN_Network.h 
     Tool/CAN/Hardware/Memory/FLASH_EEPROM_RAM_Memory.h 
     Tool/CAN/Hardware/Processor_choice.h 
     Tool/CAN/ISO_11783/ISO_11783_Enums/Enum_Auxiliary_And_General_Purpose_Valves.h 
     Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Application_Layer.h 
     Tool/CAN/Open_SAE_J1939/Open_SAE_J1939.h 
     Tool/CAN/Open_SAE_J1939/Structs.h 
     Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_Control_Byte.h 
     Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_DM1_DM2.h 
     Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_DM14_DM15.h 
     Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_Group_Function_Value.h 
     Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_NAME.h 
     Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_PGN.h 
     Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_Send_Status.h 
     Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Layer.h 
     Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Application_Layer.h 
     Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/Diagnostics_Layer.h 
     Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Network_Management_Layer.h
    

但我在Transport_Layer.h文件中仍收到一个错误

#ifndef SAE_J1939_21_TRANSPORT_LAYER_SAE_J1939_21_TRANSPORT_LAYER_H_
#define SAE_J1939_21_TRANSPORT_LAYER_SAE_J1939_21_TRANSPORT_LAYER_H_

/* Layers */
#include "../../Hardware/CAN_Network/CAN_Network.h"
#include "../../Open_SAE_J1939/Structs.h"
#include "../SAE_J1939-71_Application_Layer/Application_Layer.h"
#include "../SAE_J1939-73_Diagnostics_Layer/Diagnostics_Layer.h"
#include "../SAE_J1939-81_Network_Management_Layer/Network_Management_Layer.h" <--- This one
#include "../SAE_J1939_Enums/Enum_Control_Byte.h"
#include "../SAE_J1939_Enums/Enum_DM1_DM2.h"
#include "../SAE_J1939_Enums/Enum_DM14_DM15.h"
#include "../SAE_J1939_Enums/Enum_Group_Function_Value.h"
#include "../SAE_J1939_Enums/Enum_NAME.h"
#include "../SAE_J1939_Enums/Enum_PGN.h"
#include "../SAE_J1939_Enums/Enum_Send_Status.h"

和一个在Application_Layer.h文件中

#ifndef ISO_11783_ISO_11783_7_APPLICATION_LAYER_ISO_11783_7_APPLICATION_LAYER_H_
#define ISO_11783_ISO_11783_7_APPLICATION_LAYER_ISO_11783_7_APPLICATION_LAYER_H_

/* Layers */
#include "../../Hardware/CAN_Network/CAN_Network.h"
#include "../../ISO_11783/ISO_11783_Enums/Enum_Auxiliary_And_General_Purpose_Valves.h" <-- This one
#include "../../Open_SAE_J1939/Structs.h"
#include "../../SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Layer.h"
#include "../../SAE_J1939/SAE_J1939_Enums/Enum_PGN.h"

问题:

为什么会发生这种情况? 我已经包括在内了。Qt Creator IDE会看到这些文件。这没什么问题。但是,编译器似乎不理解这些文件的存在。

我使用的是Qt 5.15.2和C++11。

推荐答案

我找到了适合我的解决方案。您不需要.pri文件,如此处的答案所示。扔掉它。

以下是我所做的。

  1. 在Qt中右击您的项目。
  2. 选择添加现有词典(&Q)
  3. 标记要导入的词典。现在,您可以在.pro文件中看到许多.c.h文件。

提示:不要使用../../,这可能会带来麻烦。改为使用项目路径,例如

"ThirdLibrary/OpenSAEJ1939/...your_h_files.h"

完成!

这篇关于Qt当我尝试包括头文件时,没有这样的文件或词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

socks4 with asynchronous boost::asio(带有异步Boost::ASIO的socks4)
Boost ASIO HTTP client POST(增强ASIO HTTP客户端开机自检)
asio::strandlt;asio::io_context::executor_typegt; vs io_context::strand(Asio::strandlt;asio::io_context::executor_typegt;VS io_CONTEXT::Strand)
What#39;s the difference between asio::io_context and asio::thread_pool?(ASIO::IO_CONTEXT和ASIO::THREAD_POOL有什么区别?)
How to use boost::asio with Linux GPIOs(如何在Linux GPIO中使用Boost::ASIO)
Boost asio io_service vs io_context(增强ASIO io_服务与io_Context)