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")

相关推荐
AirDroid_cn1 小时前
iPhone 的5G 信号弱时,如何强制切换为4G?
5g·ios·iphone
用户19729591889115 小时前
WKWebView的重定向(objective_c)
前端·ios
lancoff19 小时前
#3 Creating Shapes in SwiftUI
ios·swiftui
lancoff20 小时前
#1 How to use Xcode in SwiftUI project
ios·swiftui
lancoff20 小时前
#2 Adding Text in SwiftUI
ios·swiftui
良逍Ai出海21 小时前
Build in Public|为什么我开始做一款相册清理 App(听说有竞品年收益40W)
ios·uni-app·ai编程·coding
笑尘pyrotechnic2 天前
LLDB进阶:使用命令行进行检查
ios·objective-c·cocoa·lldb
z***y8622 天前
Swift在iOS中的Xcode
ios·xcode·swift
AirDroid_cn2 天前
iOS 18 后台应用偷跑流量,如何限制?
macos·ios·cocoa
明君879972 天前
Flutter 图纸标注功能的实现:踩坑与架构设计
android·ios