【发布时间】:2020-10-13 16:21:10
【问题描述】:
我目前正在尝试在 IOS 上编译一个基于 QT 的项目。 我正在使用 cmake 创建和配置 .xcodeproject 和 xcode 以在设备上运行应用程序。
我成功删除了所有以前的链接器错误,现在我正在处理入口点。
我的 main.cpp 看起来像这样
int main(int argc, char **argv) {
QApplication app(argc, argv);
return app.exec();
}
这给了我以下错误:
错误:您正在调用 UIApplicationMain 之前创建 QApplication。 如果您正在编写原生 iOS 应用程序,并且只想使用 Qt 对于应用程序的某些部分,创建 QApplication 的好地方是 从您的 UIApplication 内的“applicationDidFinishLaunching”中 委托。
我在这篇文章中发现你应该重命名 main 并且 qt 会为你完成这项工作并启动应用程序生命周期
Run-time error for Qt application on ios built via CMake
#if defined(Q_OS_IOS)
extern "C" int qtmn(int argc, char** argv) {
#else
int main(int argc, char **argv) {
#endif
QApplication app(argc, argv);
return app.exec();
}
但现在我正在处理这个错误
ld:入口点 (_main) 未定义。用于架构 arm64
在第一篇文章中,他们说我应该有一个 your/qt/root/path/mkspecs/macx-ios-clang/rename_main.sh 脚本
我没有,在另一篇文章中,答案是:
重命名 main -> qtmn(源自 qt),重建 QT,并从我的 main() 调用 qt_main_wrapper。
但我不知道如何处理“重建并调用 qt_main_wrapper”
【问题讨论】:
-
我从来没有听说过替换你的 main() 来让 iOS 工作。我有一个在 iTunes Store 上发布的应用程序,无需任何特殊处理(即 iOS、android 和 win32 的 main() 不需要#ifdefs),它肯定可以正常工作。我的主要看起来像这样: int main(...) { return my_singleton::run(args) };我的 my_singleton::run() 是静态函数,如下所示: int my_singleton::run() { singleton_ = new myQApplication(args) } 其中 myQApplication 是 QApplication 的直接后代。
-
@markus-nm 谢谢,我在这里更新了我的问题forum.qt.io/topic/82102/…,看起来 Qt 没有将我的 QApplication 包装在等效的 ObjectiveC 中