You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Techlog插件开发:Qt qHash重载匹配失败编译报错求助

Techlog插件开发编译错误及无qmake问题解决

问题描述

  • 正在进行Techlog工具的插件开发,该工具提供的SDK UI基于Qt实现。
  • 引入SDK的tsdkvariable.h头文件后编译代码,出现两类错误:
    • error C2665: 'qHash': none of the 23 overloads could convert all the argument types
    • error C2056: illegal expression
  • SDK附带的Qt没有qmake,不清楚如何推进问题解决。

编译错误详情

error C2665: 'qHash': none of the 23 overloads could convert all the argument types
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(108): note: could be 'uint qHash(std::nullptr_t,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(105): note: or       'uint qHash(QLatin1String,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(104): note: or       'uint qHash(const QBitArray &,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(103): note: or       'uint qHash(QStringView,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(101): note: or       'uint qHash(const QStringRef &,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(100): note: or       'uint qHash(const QString &,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(98): note: or       'uint qHash(const QByteArray &,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(97): note: or       'uint qHash(const QChar,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(95): note: or       'uint qHash(long double,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(93): note: or       'uint qHash(double,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(92): note: or       'uint qHash(float,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(91): note: or       'uint qHash(qint64,uint) noexcept'
3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(87): note: or       'uint qHash(quint64,uint) noexcept'
1>c:\program files\schlumberger\ocean for techlog 2022.1\3rdparty\qt 5.15.2\include\qtcore\qhash.h(291): note: see reference to function template instantiation 'void QHash<T,QHashDummyValue>::detach_helper(void)' being compiled
1>        with
1>        [
1>            T=Slb::Ocean::Techlog::Droid
1>        ]
1>c:\program files (x86)\microsoft visual studio\2019\enterprise\vc\tools\msvc\14.16.27023\include\stdexcept(23): note: see reference to class template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' being compiled
1>c:\program files\schlumberger\ocean for techlog 2022.1\3rdparty\qt 5.15.2\include\qtcore\qhashfunctions.h(118): error C2056: illegal expression

解决建议

处理qHash编译错误

从错误栈可知,编译器在为Slb::Ocean::Techlog::Droid类型实例化QHash模板时,找不到匹配的qHash重载函数,导致报错。可按以下步骤排查:

  • 确认类型定义完整性:检查tsdkvariable.h是否完整包含Slb::Ocean::Techlog::Droid的类声明,避免前向声明导致的类型不完整问题。
  • 手动实现qHash重载:如果SDK未提供该类型的哈希实现,在对应命名空间下添加qHash函数:
    #include <QtCore/QHash>
    namespace Slb::Ocean::Techlog {
        uint qHash(const Droid& obj, uint seed = 0) noexcept {
            // 根据Droid的核心成员生成哈希值,示例如下:
            return qHash(obj.uniqueIdentifier(), seed); // 假设存在返回可哈希类型的方法
        }
    }
    
  • 排查非法表达式:error C2056多由语法错误或头文件包含顺序问题引发。检查qhashfunctions.h第118行附近代码,或调整Qt头文件与SDK头文件的包含顺序,确保Qt核心头文件先于SDK头文件引入。

处理无qmake的问题

Techlog的Ocean SDK默认使用MSBuild(Visual Studio)构建,无需qmake:

  • 参考SDK官方文档:查看Ocean SDK的开发手册,通常会提供Visual Studio项目模板或预配置的项目文件,直接基于MSBuild编译即可。
  • 使用CMake构建:若需自定义构建流程,可通过CMake配置项目,指定SDK和Qt路径,CMake会自动处理依赖:
    cmake_minimum_required(VERSION 3.16)
    project(TechlogPluginDemo)
    set(CMAKE_CXX_STANDARD 17)
    
    # 配置SDK和Qt路径
    set(OCEAN_SDK_ROOT "C:/Program Files/Schlumberger/Ocean for Techlog 2022.1")
    set(Qt5_DIR "${OCEAN_SDK_ROOT}/3rdparty/qt 5.15.2/lib/cmake/Qt5")
    
    find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
    include_directories("${OCEAN_SDK_ROOT}/include")
    link_directories("${OCEAN_SDK_ROOT}/lib")
    
    add_library(TechlogPluginDemo SHARED plugin_main.cpp)
    target_link_libraries(TechlogPluginDemo Qt5::Core Qt5::Widgets OceanCore) # 根据实际SDK库名调整
    
  • 联系官方支持:若以上方法无效,直接联系Schlumberger的Ocean SDK技术支持,获取针对性的构建指导。

内容的提问来源于stack exchange,提问作者NJMR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 04:45:29