Александр Панюшкин
Александр ПанюшкинDec. 24, 2019, 2:58 p.m.

Creating an iOS app in QtCreator

This article is a note to myself on the topic of creating an iOS application in the QtCreator environment.

Task: to make an application for iPhone/iPad, which can be uploaded to the AppStore. At the same time, use QtCreator tools as much as possible and Xcode minimally.

What we have:

  • MacBook Pro with macOS Catalina (ver.10.15.2) (any poppy will do, I don't know if it will work on virtual machines)
  • Xcode (ver.11.3) (required, nothing will work without it)
  • QtCreator (ver.4.10.2) and Qt 5.12.6 (latest LTS version at the time of writing)
  • iPhone 7 Plus for performance testing
  • Some amount of time, nerves and perseverance to figure everything out.

Run test application

The application for which I dealt with the issue of installation on iOS works with the user's map and geolocation, so for this article we will take the application from standard examples - Places Map (QML) ( link ).

We copy the example (we will make small additions to it) and open it in QtCreator.

We select a suitable whale (I did not use the simulator from QtCreator):

Configuration file

And the first thing we have to do is build the project.

Then we go to the build folder (in my case it is /Users/ap/Downloads/build-places_map-Qt_5_12_6_for_iOS-Debug) we take the Info.plist file from there, which we transfer to the ios folder, which we create in the root of our project.

We add the Info.plist file to our project.

We get the following project structure:

It remains to add our file to the assembly. To do this, add the following code to the *.pro file - places_map.pro:

ios {
    QMAKE_INFO_PLIST = ios/Info.plist
}

We make this addition only for the ios platform.

Now, when building the project, our Info.plist will always be used.

Version, company, executable

We make additions to the *.pro file. We add information about the version, our company and the name of the executable file (do not confuse the name that will be displayed to the user on the phone).

VERSION = 0.1.1

QMAKE_TARGET_BUNDLE_PREFIX = "ru.mycompany"
QMAKE_BUNDLE = "places_map"
TARGET = "places_map"

QMAKE_BUNDLE and TARGET point to the same thing. I did not understand the fundamental differences between them. And in general, they are not mandatory (unless it is important for you that the name of the executable file differs from the name of the project).

The version is required. Without a version, the project will not compile.

These options are not platform specific.

Minimum iOS version

In the *.pro file, you can also specify the minimum version of iOS on which your application will run.

> Much to my regret, I didn't find any signs indicating which versions of Qt components work with. It would be logical to assume that Qt itself will be able to calculate the minimum version during the build and substitute it, but, unfortunately, I had to act randomly. Perhaps I just did not find the necessary information and I will be glad if they tell me where to look for it.

To do this, add the following line to the ios *.pro section of the file:

QMAKE_IOS_DEPLOYMENT_TARGET =9.0

In the above example, the minimum version is 9.0.

If the string is not specified, the most recent version will be substituted (currently it is 11).

Application name

> In a number of cases, I could not find a way to enter parameters only in *.pro file, I had to register directly in Info.plist. In my opinion, this is not entirely correct, so I will be grateful if they tell me how this data could be entered into * .pro and not touch Info.plist.

To change the name of the application (the name that the iOS user will see), you need to change the value (string) of the key (key) CFBundleDisplayName in the Info.plist file. For example, like this:

<key>CFBundleDisplayName</key>
<string>Places Map</string>

Using geolocations

To use geolocation, microphone, camera, etc. services, you must specify a request for permission in the Info.plist file about this. This is done by adding special keys.

In case we need to request permission to use geolocation while using the app, we use the NSLocationWhenInUseUsageDescription key. In the key value, we must specify a description that will be visible to the user, in which we need to indicate the reason why we need this service. Without this description, your program may be blocked on the AppStore.

<key>NSLocationWhenInUseUsageDescription</key>
<string>This app uses a user's locations to find nearest pizza.</string>

More information about the keys used can be found in the iOS documentation.

Application icons

An important stage is the creation of application icons. Without them, your application will not be added to the AppStore.

Details on creating icons for different versions are described in the instructions on the qt.io website - https://doc.qt.io/qt-5/ios-platform-notes.html.

I made everything easier. We need a 1024x1024 file with our icon.

We go to the site https://www.iconsgenerator.com/Home/AppIcons (there are others, but this one generated all the necessary sizes, which other services could not boast of), upload our file and download the generated icons.

Let's get the Assets.xcassets folder (the name is not important, the extension is important), which will contain our icons and json files with attached sizes according to device types.

We add this folder to our project in the ios folder.

Then it remains for us to add information about our icons to the ios section of the * .pro file:

    QMAKE_ASSET_CATALOGS += ios/Assets.xcassets

Loading screen

This step is optional as a simple boot screen with the name of your executable will be created on build. But you must admit, with a beautiful boot picture, the application looks better. So let's create our own.

Let's create a logo file. Let's name it, for example, CustomScreenLogo.png . Place it in the ios folder and add it to the project.

Now you need to build the project, go to the build folder and find the xcodeproj file. In our case, this is places_map.xcodeproj . We right-click on it and go to its contents. Copy the file LaunchScreen.xib to the ios folder of our application and rename it to CustomScreen.xib .

It is important that the extension be xib in the name, and LaunchScreen does not appear in the name.

> It is worth noting that according to information on various sites, Apple is now gradually trying to transfer everyone to the Storyboard. But I still tried to use the xib file option, as suggested in the Qt documentation.

Add the following lines to the *.pro file in the ios section:

    app_launch_screen.files = $$PWD/ios/CustomScreen.xib $$files($$PWD/ios/CustomScreenLogo.png)
    QMAKE_BUNDLE_DATA += app_launch_screen

And in the Info.plist file, in the UILaunchStoryboardName key, we specify CustomScreen (the name of our xib file without extension).

And rebuild the project. And run the xcodeproj file in Xcode.

In the BundleData folder we should now have our added files:

Open the CustomScreen.xib file.

Delete labels Label and places_map. We click on the plus sign in the upper right part and add the Image VIew element to the View section. And on the right side in the Image section, select our CustomScreenLogo.png logo.

Open the Size Inspector tab and specify Autoresizing so that our logo changes size on different devices.

It is also worth changing the background color of the View.

Then we save everything, close Xcode and build the project again in QtCreator.

Health check

Now you can run the project on your iOS device and check if it works.

I will not talk about how to put the project in the AppStore - it is completely ready for uploading like a regular Xcode project, and there are quite a lot of instructions on the net on how to do this. For unloading only, use the Release assembly.

Used materials

Platform Notes - iOS

QMAKE Variable reference

Icon generator

Questions I have left

  • How to check that the user has allowed the use of geolocation and other services? How to request permission while the application is running as needed?
  • One error pops up while building -
    AppIcon.appiconset/[][ipad][76x76][][][1x][][]:-1: error: notice: 76x76@1x app icons only apply to iPad apps targeting releases of iOS prior to 10.0.
    . It can be avoided by writing icons directly in Info.plist, but such writing then prevents the program from being uploaded to the AppStore. In theory, the error does not interfere with anything, but it is annoying. Is there a way to somehow remove it?
  • How can I set the size of the image in the article? And it was painfully big some of the pictures turned out.
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Алексей Внуков
  • Dec. 26, 2019, 5:17 a.m.

для последнего Xcode и для последних версий iOS нужно брать Qt 5.14.
по поводу виртуалки - все работает нормально но без сборки на живой айфон у меня не получилось получить бинарник который принимает стор.
согласно последним соглашениям в Info.plist дожны быть обязательно указаны поля NSCameraUsageDescription, NSLocationAlwaysUsageDescription, NSLocationWhenInUseUsageDescription.
после первого создания Info.plist и вносения в него изменений - рекомендую его бекапить, посколько при каждой сборке он будет перезатираться

Comments

Only authorized users can post comments.
Please, Log in or Sign up
AD

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:50points,
  • Rating points-4
m

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:80points,
  • Rating points4
m

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:20points,
  • Rating points-10
Last comments
ИМ
Игорь МаксимовNov. 22, 2024, 8:51 a.m.
Django - Tutorial 017. Customize the login page to Django Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Evgenii Legotckoi
Evgenii LegotckoiOct. 31, 2024, 11:37 a.m.
Django - Lesson 064. How to write a Python Markdown extension Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
A
ALO1ZEOct. 19, 2024, 5:19 a.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Игорь МаксимовOct. 5, 2024, 4:51 a.m.
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
d
dblas5July 5, 2024, 8:02 a.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Now discuss on the forum
Evgenii Legotckoi
Evgenii LegotckoiJune 24, 2024, 12:11 p.m.
добавить qlineseries в функции Я тут. Работы оень много. Отправил его в бан.
t
tonypeachey1Nov. 15, 2024, 3:04 a.m.
google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
NSProject
NSProjectJune 4, 2022, 12:49 a.m.
Всё ещё разбираюсь с кешем. В следствии прочтения данной статьи. Я принял для себя решение сделать кеширование свойств менеджера модели LikeDislike. И так как установка evileg_core для меня не была возможна, ибо он писался…
9
9AnonimOct. 25, 2024, 6:10 a.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…

Follow us in social networks