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

Mac Qt应用在Qt Creator可运行,经macdeployqt打包后崩溃

Qt应用在M2 Mac Mini上经macdeployqt打包后启动崩溃问题及解决方法

问题背景

我有一个Qt应用,此前在2014款Mac Mini上使用Qt 5.15.1开发,可在Qt Creator中正常构建,经macdeployqt打包生成.dmg文件后能正常分发运行。升级至搭载M2处理器的2023款Mac Mini后,应用在Qt Creator 12.0.1中仍可正常构建运行,但通过命令行构建并使用macdeployqt打包后,启动时会在相关线程函数中崩溃。

崩溃信息

Qt 5.15.x版本崩溃报告片段

Process:               CartoTypeMaps [14478]
Path:                  /Volumes/VOLUME/CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps
Identifier:            com.yourcompany.CartoTypeMaps
Version:               ???
Code Type:             X86-64 (Translated)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-12-28 09:50:05.1807 +0000
OS Version:            macOS 13.5 (22G74)
Report Version:        12
Anonymous UUID:        E937E16C-6079-DC90-55E4-74D065DDB839


Time Awake Since Boot: 5300 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 6 Abort trap: 6
Terminating Process:   CartoTypeMaps [14478]

Application Specific Information:
abort() called


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                                 0x7ff89a48a9a8 ???
1   libsystem_kernel.dylib              0x7ff80a843202 __pthread_kill + 10
2   libsystem_pthread.dylib             0x7ff80a87aee6 pthread_kill + 263
3   libsystem_c.dylib                   0x7ff80a7a1b45 abort + 123
4   libc++abi.dylib                     0x7ff80a835282 abort_message + 241
5   libc++abi.dylib                     0x7ff80a8273e1 demangling_terminate_handler() + 241
6   libobjc.A.dylib                     0x7ff80a4fba7f _objc_terminate() + 104
7   libc++abi.dylib                     0x7ff80a8346db std::__terminate(void (*)()) + 6
8   libc++abi.dylib                     0x7ff80a836fa7 __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 27
9   libc++abi.dylib                     0x7ff80a836f6e __cxa_throw + 116
10  CartoTypeMaps                          0x103068463 CartoTypeCore::CVectorTileServer::CVectorTileServer(CartoTypeCore::Framework&, unsigned long, unsigned long) + 1525

Qt 6.6.1版本崩溃报告片段

Process:               CartoTypeMaps [20293]
Path:                  /Volumes/VOLUME/CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps
Identifier:            com.yourcompany.CartoTypeMaps
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-12-28 10:22:19.6461 +0000
OS Version:            macOS 13.5 (22G74)
Report Version:        12
Anonymous UUID:        E937E16C-6079-DC90-55E4-74D065DDB839


Time Awake Since Boot: 7200 seconds

System Integrity Protection: enabled

Crashed Thread:        47

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 6 Abort trap: 6
Terminating Process:   CartoTypeMaps [20293]

Application Specific Information:
abort() called


Thread 0::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib                 0x1aa127750 __psynch_cvwait + 8
1   libsystem_pthread.dylib                0x1aa164574 _pthread_cond_wait + 1232
2   libc++.1.dylib                         0x1aa08cef0 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3   QtCore                                 0x1033af1b4 QSemaphore::acquire(int) + 80
4   QtGui                                  0x101b022dc 0x1016a0000 + 4596444
5   QtGui                                  0x101ae452c 0x1016a0000 + 4474156
6   QtGui                                  0x1017e7800 0x1016a0000 + 1341440
7   QtGui                                  0x10180d358 0x1016a0000 + 1495896
8   QtGui                                  0x10180f844 QRasterPaintEngine::fill(QVectorPath const&, QBrush const&) + 1248

注意:Qt 6.6.1版本在ARM-64(原生)和X86-64(转译)两种架构下崩溃情况完全一致。

排查过程

  • 先后测试Qt 5.15.1、5.15.2及Qt 6.6.1版本,崩溃现象一致
  • 最初怀疑打包后的应用调用了错误的动态库,但未找到相关证据
  • 通过命令行直接启动.app内的可执行文件,得到明确错误提示:
./CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps
QThreadPipe: Unable to create pipe: Too many open files
QEventDispatcherUNIXPrivate(): Cannot continue without a thread pipe
zsh: abort      ./CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps

解决方案

问题根源在于M2 Mac Mini默认的最大文件打开数仅为256,数值过低导致Qt线程管道创建失败。

临时解决(仅当前终端有效)

在终端运行以下命令,提高当前进程的文件打开限制:

ulimit -n 10240

此方法仅对终端启动的应用有效,双击.dmg内的应用图标启动时无效。

系统级永久解决

执行以下两条命令(缺一不可),修改系统级的文件打开限制:

sudo launchctl limit maxfiles 256 unlimited
sudo launchctl limit maxfiles 128000 524288

后续疑问

  • 需进一步排查应用为何会触发文件打开数限制,目前认为应用本身仅打开40-50个文件,推测256的限制是系统级而非单应用级
  • Qt Creator中运行应用一切正常,推测Qt Creator会为其启动的进程自动提高文件打开限制

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 09:54:51