3

When I create a QtWidgets application, select iphonesimulator-clang Qt5.3, and run the app in debug mode on the iOS simulator I get the error below. I am not adding any code; just running the Qt Creator template code.

"Error: You are creating QApplication before calling UIApplicationMain. If you are writing a native iOS application, and only want to use Qt for parts of the application, a good place to create QApplication is from within 'applicationDidFinishLaunching' inside your UIApplication delegate.”

I have Qt5.3.1 (installed using the online installer) and Xcode 5.1.1.

Running the provided Calculator Example on the iOS simulator works fine without the error.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • There is no "auto generated" code, it's just a template that came with Qt Creator. Those templates are often sub-par. Copy a simple example instead, then remove the functionality and you'll have a decent template to start with. – Kuba hasn't forgotten Monica Aug 17 '14 at 23:56
  • Thanks for the tip. That works. Still, I am interested in knowing why i get the error. Googled but could not find what i was looking for. So if you have any pointers that would be appreciated... –  Aug 21 '14 at 20:52
  • After some more searching i found a workaround here http://www.sheim.net/wordpress/computer/tipps-und-tricks/ –  Aug 21 '14 at 21:17
  • see https://stackoverflow.com/questions/45508043/qt-ios-linker-error-entry-point-main-undefined for an updated fix for this issue – Alan Birtles Feb 27 '23 at 09:58

1 Answers1

4

Just in case the solution decided to disappear elsewhere: the fix is to change the signature of the main function.

#if defined(Q_OS_IOS)
extern "C" int qtmn(int argc, char **argv)
#else
int main(int argc, char **argv)
#endif
{
  ...
}
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313