Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting
TIMEWEB

Development on Qt for iOS

ios, qt

Preamble

The most democratic country in the world has created the most totalitarian operating system. Therefore, if you want to test your software on an iPad or IPhone, you must register with https://developer.apple.com/ as a developer. At the first stage, you do not have to pay money. Good Uncle Jobs will give you a certificate, for use to test your device, for a period of 7 (seven) days. At the end of the certificate, your software will not start and it will need to be downloaded again from the computer. If you want to install your software on another person's device - its apple ID will need to be written in the same way in Xcode as yours.

Problems

To study Qt, I decided to develop a mobile workplace for the workflow for the test task. Because the documents can be in the form of word, pdf, jpg, etc. I naturally need after downloading them from the server something to open them. Qt has a wonderful design

QDesktopServices :: openUrl ( QUrl :: fromLocalFile ( QStandardPaths :: writableLocation ( QStandardPaths :: GenericDataLocation ) + "/temp_esd/file." + file_ext ));
// File _ ext I pull out according to the MIME type
if ( head == "Content-Type" ) {
    if ( content_from_url == "image/jpeg" )
        file_ext = "jpg";
    else if ( content_from_url == "application/pdf" )
        file_ext = "pdf";
    else if ( content_from_url == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" )
        file_ext = "docx";
    else if ( content_from_url == "application/msword" )
        file_ext = "doc";
    else if ( content_from_url == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" )
        file_ext = "xlsx";
    else if ( content_from_url == "application/vnd.ms-excel" )
        file_ext = "xls";
    else if ( content_from_url == "application/vnd.oasis.opendocument.text" )
        file_ext = "odt";
    else if ( content_from_url == "application/vnd.oasis.opendocument.spreadsheet" )
        file_ext = "ods";
    else if ( content_from_url == "application/octet-stream" )
        file_ext = "7z";
    else if ( content_from_url == "video/x-msvideo" )
        file_ext = "avi";
    else if ( content_from_url == "image/bmp" )
        file_ext = "bmp";
    else if ( content_from_url == "application/cdr" )
        file_ext = "cdr";
    else if ( content_from_url == "image/gif" )
        file_ext = "gif";
    else if ( content_from_url == "video/quicktime" )
        file_ext = "mov";
    else if ( content_from_url == "audio/mpeg" )
        file_ext = "mp3";
    else if ( content_from_url == "image/png" )
        file_ext = "png";
    else if ( content_from_url == "application/vnd.ms-powerpoint" )
        file_ext = "ppt";
    else if ( content_from_url == "application/vnd.openxmlformats-officedocument.presentationml.presentation" )
        file_ext = "pptx";
    else if ( content_from_url == "application/x-rar-compressed" )
        file_ext = "rar" ;
    else if ( content_from_url == "application/rtf" )
        file_ext = "rtf";
    else if ( content_from_url == "image/tiff" )
        file_ext = "tif";
    else if ( content_from_url == "text/plain" )
        file_ext = "txt" ;
    else if ( content_from_url == "audio/x-ms-wma" )
        file_ext = "wma";
    else if ( content_from_url == "application/zip" )
        file_ext = "zip";
}

But in iOS - in accordance with the recently adopted security standards it is forbidden to open a local URL in one application by running another one. Therefore, under IOS, the use of this construction caused an error

this plugin does not support

First I went in the direction of using Info.plist - especially since under iOS it is still needed. Registered in section

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>ms-word</string> 
        <string>ms-powerpoint</string> 
        <string>ms-excel</string>
    </array>

But this works only if the files are opened NOT locally - but on the Internet link. After further study of the problem, I came across the article https://code.tutsplus.com/tutorials/ios-sdk-previewing-and-opening-documents--mobile-15130 which describes how to use the UIDocumentInteractionController to open files in the sandbox of the ios application . Also thank you very much Ekkehard Gentz for a completely wonderful blog, which details the use of the above function in Qt.

Solution

And so we have a MAC MINI for compiling source and IPAD for testing. On the MAC MINI install QT. During the installation you will be offered to download XCODE - we agree. Everything is perfectly established. Next, in Xcode - Preferences - Accounts, add your Apple account and request a certificate (via Manage Certificates). Naturally, you must first register on the Apple website as a developer. Next, connect your IPAD and in the Settings - Developer - UI AUTOMATION - enable Enable UI Automation. Thus, we have transferred the iPad to the debugged mode.

In Xcode - Window - Devices and Simulators, you can check your connected device. Of course, during the connection you will be asked a couple of times about the trust of the computer to the device and the device of the computer - say YES.

In the Qt in the project file, add the following section

ios {
OBJECTIVE_SOURCES += ios/iosshareutils.mm \
ios/docviewcontroller.mm

QMAKE_INFO_PLIST = ios/Info.plist

LIBS += - framework UIKit
}

In this section we specify the location of Info.plist - this is a textual configuration file that you can edit manually.

OBJECTIVE_SOURCES are our files on OBJECTIVE- C

The LIBS directive is probably outdated. But I did not remove it.

In the sources themselves it is very convenient to use the directive

#if defined( Q_OS_IOS )

QString temp_url= QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/temp_esd/file." +file_ext;
qDebug() << "path_file " << temp_url;
IosShareUtils ios;
ios.viewFile(temp_url, "View File" , "application/pdf" , 21 );

#else
QDesktopServices :: openUrl ( QUrl :: fromLocalFile ( QStandardPaths :: writableLocation ( QStandardPaths :: GenericDataLocation ) + "/temp_esd/file." + file_ext ));
#endif

You can see the source code in the blog https://blog.qt.io/blog/2017/12/01/sharing-files-android-ios-qt-app/

In general, after the source texts are ready, we proceed to the de-file. Please note that in Qt Creator when you release on Qt 5.10 for iOS, the green dot on the right below the icon of the phone with the apple is burning. Hover over it and see the information about the device and whether it works in developer mode. After that, we compile the sources and try to upload them to the phone. From the first time does not work. Go to the Release folder and open the Xcode project of our application. At the top, where the name of your circuit is, select the active circuit on the device that is connected to the computer. Then click on the "Build and then run the current scheme" icon. But that is not all. Your application icon will appear on your device, but it will not start. Or it will start, but it will close quickly. Open the Ipad - go to settings - basic - device management - software developer - choose your apple id - then we say that we trust this developer. After all these operations, you can safely unplug the application directly from Qt Creator.

Thanks to all of the internet who patiently answered my stupid questions. And God will forgive those who tried to shake me off money. It seems to me - some kind of altruism should be present for every professional.

10% refund of hotel reservation amount on Booking
10% refund of hotel reservation amount on Booking
We offer a link with a 10% return on the amount of the order when booking a hotel through Booking

Вот честно, на сколько же муторно под огрызок что то делать. Куча проблем)
А вод линь или под Андроид все просто и тривиально))

Comments

Only authorized users can post comments.
Please, Log in or Sign up
МБ
April 21, 2019, 9:40 a.m.
Моисей Бушуев

Qt - Test 001. Signals and slots

  • Result:0points,
  • Rating points-10
AA
April 17, 2019, 7:40 p.m.
Anton Ablin

Qt - Test 001. Signals and slots

  • Result:73points,
  • Rating points1
E
April 17, 2019, 6:16 p.m.
Evgeny

Qt - Test 001. Signals and slots

  • Result:100points,
  • Rating points10
Last comments
April 21, 2019, 4:22 p.m.
Евгений Легоцкой

Через метод setIcon table.horizontalHeaderItem(0).setIcon("qrc://path/to/icon.png")
April 21, 2019, 3:48 p.m.
Евгений Легоцкой

Добрый день! Спасибо за комментарий. Там действительно лучше будет сделать с инициализацией по умолчанию.
U
April 18, 2019, 3:37 p.m.
Unreal_man

А как иконку в хедер задать?
u
April 18, 2019, 2:15 a.m.
uaa

доброго времени,большое спасибо за пример для начинающего)при адаптации к своему проекту столкнулся с таким ньансом:в vepolyline.h в 47 строке нужна инициализация по умолчанию: int m_pointF...
E
April 11, 2019, 12:49 p.m.
Evgeny

Спасибо за ответ) У меня компоновщик на нее ругался просто. Оказалось, просто забыл Q_OBJECT в начале класса указать.
Now discuss on the forum
April 24, 2019, 11:22 a.m.
Ruslan Polupan

Согласен. но ситуация не поменялась. Такое чуство что данные не записываются в модель.
April 24, 2019, 6:20 a.m.
Ruslan Polupan

я так понимаю надо инфорация об устройствах.Я бы пробовал так rust@suse:~> lsblk -PNAME="sda" MAJ:MIN="8:0" RM="0" SIZE="111,8G" RO="0" TYPE="disk" MOUNTPOINT=""NAME="sda1" MAJ:MIN="8...
April 21, 2019, 4:16 p.m.
Евгений Легоцкой

Приветствую Нужно сохранять где-то выбранное значение, а потом восстанавливать его. Или использовать QSettings или добавить метод open(), в который передавать начальные значения для того...
R
April 19, 2019, 9:55 a.m.
RED_Spider

мені важко це зараз навіть перевірити, тому що знайшов коміт, це ще було в 2016 році, і цей код не буде працювати коректно зараз, єдине скажу що це були QThread
Join us in social networks

For registered users on the site there is a minimum amount of advertising