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/[email protected]/include")
    set (SSL_LIBRARY "/usr/local/opt/[email protected]/lib/libssl.a")
    set (CRYPTO_LIBRARY "/usr/local/opt/[email protected]/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

ios qt开发要点_第1张图片

参考来源: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")

你可能感兴趣的:(ios,qt5,cmake,openssl)