-1

I solve the problem.

#include <QtCore/private/qandroidextras_p.h>

The private folder is not included in the qtcore folder.

private folder is included in the "6.4.2(qt version)" folder. you have to copy the private folder to first QtCore folder.

and if you include "QtCore/private/qandroidextras_p.h", it will succeed.

and Refer to this article and request for permission, and it will succeed.

Requesting Android permissions in Qt 6

I hope this article will be helpful to others.

keehl
  • 43
  • 2
  • 9
  • 2
    When you installed Qt, did you install the Qt for Android packages? – Some programmer dude Jan 03 '23 at 13:39
  • yes I installed Android package. building a android apps success. but there are no QtAndroid.h header file – keehl Jan 03 '23 at 13:52
  • https://amin-ahmadi.com/2015/11/29/how-to-add-permissions-to-your-qt-android-app/ – Chnossos Jan 03 '23 at 14:33
  • I already added AndroidManifest.xml file and also add permission. I want to know how to request permission in c++ – keehl Jan 03 '23 at 14:39
  • "On Internet some guys said..." is not really a trustworthy source. What does the actual Qt documentation say? – Some programmer dude Jan 03 '23 at 15:48
  • I got source code. It use QtAndroid header file. auto result = QtAndroid::checkPermission(QString("android.permission.CAMERA")); if(result == QtAndroid::PermissionResult::Denied){ QtAndroid::PermissionResultMap resultHash = QtAndroid::requestPermissionsSync(QStringList({"android.permission.CAMERA"})); if(resultHash["android.permission.CAMERA"] == QtAndroid::PermissionResult::Denied) return 0; } I think I have to use QtAndroid.h header file – keehl Jan 04 '23 at 02:08
  • Have you tried to read some [***documentation***](https://doc.qt.io/qt-5/qtandroid.html)? What header file does that documentation tell you to include? The first source of information should always be official documentation, and unless it's from a reputable source the ***last*** should be "some guy on the Internet". – Some programmer dude Jan 04 '23 at 07:15
  • I read that document. but There is no 'QtAndroid' header file in my environment. I think its wierd so I posted this article...Thanks for your comments – keehl Jan 04 '23 at 08:31
  • A quick check on [the 5-to-6 feature matrix](https://www.qt.io/product/qt6/qt-5-15-vs-6-2-feature-comparison) Android support have been moved into the base modules, it no longer exists as a separate module. So you should just be able to build as any other Qt application, but with the correct target. So how do you build? What is your development environment? Are you using CMake or Qt `.pro` project files? – Some programmer dude Jan 04 '23 at 09:00
  • Also please read [Qt for Android - Building User Projects](https://doc.qt.io/qt-6/android-building-user-projects.html) – Some programmer dude Jan 04 '23 at 09:01
  • Thanks for your comments again. I'll try again when I arrive at home. – keehl Jan 04 '23 at 09:09
  • 1
    Please do not add answers to the question body itself. Instead, you should add it as an answer. [Answering your own question is allowed and even encouraged](https://stackoverflow.com/help/self-answer). – Adriaan Jan 10 '23 at 13:27

2 Answers2

0

I solved the probelm.

The QtAndroid.h file has been replaced with qandroidextras_p.h on 6.2

https://doc.qt.io/qt-6/qtandroidprivate.html#requestPermission-1

we have to include header file, like this

#include <6.4.2(qt version)/QtCore/private/qandroidextras_p.h> 

But when I include this header file, on Error message, it can't find the included header file in the qandroidextras_p.h file. This part seems to need to edit the included header file path of the qandroidextras_p.h file.

keehl
  • 43
  • 2
  • 9
0

I succeeded in getting file permissions.

There is header file

#include <QtCore/private/qandroidextras_p.h>

I have to copy the private(QtCore/6.4.2/QtCore/[private]/qandroidextras_p.h) folder to first QtCore folder.

if you don't copy this folder, compiler can't find the some header files that declared on qandroidextras_p.h file.

and add the permission on AndroidManifest.xml file

  1. Request Permission function Requesting Android permissions in Qt 6

  2. Create Android Manifest file Where did the "Create AndroidManifest.xml" button go in Qt Creator 3.3.0?

  3. Search file on qt Recursively iterate over all the files in a directory and its subdirectories in Qt

when search files on android, root path is must be '/storage/emulated/0;' or '/mnt/sdcard'. not the QDir::rootPath();

keehl
  • 43
  • 2
  • 9