ios qt开发要点

目前关于ios qt的开发资料比较少,这里整理了几个比较重要的开发要点,基于MacOS14 + Xcode15 + Qt5.15 + cmake + iphone真机。

  • cmake报错,报错信息如下

    CMake Error at /Users/user/Qt/5.15.5/ios/lib/cmake/Qt5Core/Qt5CoreConfig.cmake:91 (message):
    Library not found: MobileCoreServices
    Call Stack (most recent call first):
    /Users/user/Qt/5.15.5/ios/lib/cmake/Qt5Core/Qt5CoreConfig.cmake:263
    (_qt5_Core_process_prl_file)
    /Users/user/Qt/5.15.5/ios/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)
    CMakeLists.txt:28 (find_package)

解决方法:添加cmake参数

-DCMAKE_FIND_ROOT_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_SYSTEM_NAME=iOS
-DCMAKE_OSX_SYSROOT=iphoneos
-DCMAKE_OSX_ARCHITECTURES=arm64

并在CMakeLists.txt中添加

if(IOS)
    target_link_options(${user_project_target_name} PRIVATE "-Wl,-e,_qt_main_wrapper")
endif()

参考来源:https://bugreports.qt.io/browse/QTCREATORBUG-26121

  • 找不到openssl,报错如下

    Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
    system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)
    

实测设置OPENSSL_ROOT_DIR无效,这里可以手动指定相应的cmake变量,在FindOpenSSL.cmake做相应的修改。

FIND_PATH(OPENSSL_INCLUDE_DIR
  NAMES
    openssl/ssl.h
  PATH_SUFFIXES
	"include"
  HINTS
    ${_OPENSSL_INCLUDEDIR}
  ${_OPENSSL_ROOT_HINTS_AND_PATHS}
  PATH_SUFFIXES
    include
)

# add for ios
IF(IOS AND NOT OPENSSL_INCLUDE_DIR)
    set (OPENSSL_INCLUDE_DIR "/usr/local/opt/opensslios@1.1/include")
    set (SSL_LIBRARY "/usr/local/opt/opensslios@1.1/lib/libssl.a")
    set (CRYPTO_LIBRARY "/usr/local/opt/opensslios@1.1/lib/libcrypto.a")
    list(APPEND OPENSSL_LIBRARIES ${CRYPTO_LIBRARY} ${SSL_LIBRARY})
ENDIF()
  • 打开.pro项目文件报错,无法展开项目文件树

    failed to parse default search paths from compiler output

解决方法:在qmake构建步骤添加额外参数

 -early QMAKE_DEFAULT_LIBDIRS=$(xcrun -show-sdk-path)/usr/lib

参考来源:https://bugreports.qt.io/browse/QTBUG-117225

  • 设置AppIcon无效,解决方法:1)在Xcode中将xcassets文件添加到Build Phases中的Copy Bundle Resources中;2)也可以在cmake如下添加:

    set_target_properties(${MODULE_NAME} PROPERTIES RESOURCE "xxx.xcassets")

相关推荐
如何学会学习?1 小时前
10. zynq应用开发--camke编译
cmake·zynq·petalinux·mpsoc·acu106·zcu106
app开发工程师V帅9 小时前
iOS 苹果开发者账号: 查看和添加设备UUID 及设备数量
ios
CodeCreator18189 小时前
iOS AccentColor 和 Color Set
ios
iOS民工10 小时前
iOS keychain
ios
m0_7482389213 小时前
webgis入门实战案例——智慧校园
开发语言·ios·swift
Legendary_00817 小时前
LDR6020在iPad一体式键盘的创新应用
ios·计算机外设·ipad
/**书香门第*/1 天前
Laya ios接入goole广告,搭建环境 1
ios
wakangda1 天前
React Native 集成 iOS 原生功能
react native·ios·cocoa
crasowas2 天前
iOS - 超好用的隐私清单修复脚本(持续更新)
ios·app store
ii_best2 天前
ios按键精灵脚本开发:ios悬浮窗命令
ios