Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Error when using checkPermissions
Forum Update on Monday, May 27th 2025

Error when using checkPermissions

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
androidpermissions
4 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GangsterV
    wrote on 27 Feb 2021, 13:52 last edited by
    #1

    Hi guys,

    I'm developing an android app where I have to store some data and retrieve it when the app opens again. The problem is, I can't create a file in any place except the internal storage, but I need it in the external storage so that I can actually check the file and see what it contains.

    I could narrow this down to be a permissions problem, so I tried create some code to request for permissions at the start and checked previous threads, but I got a very unexpected error.

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include "helper.h"
    #include <QtAndroidExtras/QtAndroid>
    
    int main(int argc, char *argv[])
    {
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
    
        QGuiApplication app(argc, argv);
    
    
        const QVector<QString> permissions({"android.permission.WRITE_EXTERNAL_STORAGE",
                                            "android.permission.READ_EXTERNAL_STORAGE"});
    
            for(const QString &permission : permissions){
                auto result = QtAndroid::checkPermission(permission);
                if(result == QtAndroid::PermissionResult::Denied){
                    auto resultHash = QtAndroid::requestPermissionsSync(QStringList({permission}));
                    if(resultHash[permission] == QtAndroid::PermissionResult::Denied)
                        return -1;
                }
            }
    
        QQmlApplicationEngine engine;
    
        qmlRegisterType<Helper>("com.masternuts.helper", 1, 0, "Helper");
    
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    
    

    This is my main.cpp. What I'm getting is "undefined reference to 'QtAndroid::checkPermission(QString const&)'", and the same error for requestPermissionsSync.

    I tried checking the definition of these functions and they do exist in the qtandroidextras module of my Qt installation. What could possibly be wrong here?

    For extra information, I'm using Qt 5.12.3, building on Android arm64-v8a using qmake.

    I know this could be a silly error, but I'm still not so familiar with how everything in Qt works. Any help would be appreciated.

    Thanks in advance :)

    K J 3 Replies Last reply 27 Feb 2021, 14:27
    0
    • G GangsterV
      27 Feb 2021, 13:52

      Hi guys,

      I'm developing an android app where I have to store some data and retrieve it when the app opens again. The problem is, I can't create a file in any place except the internal storage, but I need it in the external storage so that I can actually check the file and see what it contains.

      I could narrow this down to be a permissions problem, so I tried create some code to request for permissions at the start and checked previous threads, but I got a very unexpected error.

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include "helper.h"
      #include <QtAndroidExtras/QtAndroid>
      
      int main(int argc, char *argv[])
      {
      #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      #endif
      
          QGuiApplication app(argc, argv);
      
      
          const QVector<QString> permissions({"android.permission.WRITE_EXTERNAL_STORAGE",
                                              "android.permission.READ_EXTERNAL_STORAGE"});
      
              for(const QString &permission : permissions){
                  auto result = QtAndroid::checkPermission(permission);
                  if(result == QtAndroid::PermissionResult::Denied){
                      auto resultHash = QtAndroid::requestPermissionsSync(QStringList({permission}));
                      if(resultHash[permission] == QtAndroid::PermissionResult::Denied)
                          return -1;
                  }
              }
      
          QQmlApplicationEngine engine;
      
          qmlRegisterType<Helper>("com.masternuts.helper", 1, 0, "Helper");
      
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      
      

      This is my main.cpp. What I'm getting is "undefined reference to 'QtAndroid::checkPermission(QString const&)'", and the same error for requestPermissionsSync.

      I tried checking the definition of these functions and they do exist in the qtandroidextras module of my Qt installation. What could possibly be wrong here?

      For extra information, I'm using Qt 5.12.3, building on Android arm64-v8a using qmake.

      I know this could be a silly error, but I'm still not so familiar with how everything in Qt works. Any help would be appreciated.

      Thanks in advance :)

      K Offline
      K Offline
      KroMignon
      wrote on 27 Feb 2021, 14:27 last edited by KroMignon
      #2

      @GangsterV said in Error when using checkPermissions:

      I know this could be a silly error, but I'm still not so familiar with how everything in Qt works. Any help would be appreciated.

      I don't know if it will resolve your problem, but QtAndroid::checkPermission() is only required for Android 6.0 (Marshmallow / API Level 23) and upper. For older Android version, the permisisons are set thought Manifest settings.

      You could add this check in your code:

      if(QtAndroid::androidSdkVersion() >= 23)
      {
          const QVector<QString> permissions({"android.permission.WRITE_EXTERNAL_STORAGE",
                                              "android.permission.READ_EXTERNAL_STORAGE"});
      
          for(const QString &permission : permissions){
              auto result = QtAndroid::checkPermission(permission);
              if(result == QtAndroid::PermissionResult::Denied){
                  auto resultHash = QtAndroid::requestPermissionsSync(QStringList({permission}));
                  if(resultHash[permission] == QtAndroid::PermissionResult::Denied)
                      return -1;
              }
          }
      }
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      0
      • G GangsterV
        27 Feb 2021, 13:52

        Hi guys,

        I'm developing an android app where I have to store some data and retrieve it when the app opens again. The problem is, I can't create a file in any place except the internal storage, but I need it in the external storage so that I can actually check the file and see what it contains.

        I could narrow this down to be a permissions problem, so I tried create some code to request for permissions at the start and checked previous threads, but I got a very unexpected error.

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include "helper.h"
        #include <QtAndroidExtras/QtAndroid>
        
        int main(int argc, char *argv[])
        {
        #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        #endif
        
            QGuiApplication app(argc, argv);
        
        
            const QVector<QString> permissions({"android.permission.WRITE_EXTERNAL_STORAGE",
                                                "android.permission.READ_EXTERNAL_STORAGE"});
        
                for(const QString &permission : permissions){
                    auto result = QtAndroid::checkPermission(permission);
                    if(result == QtAndroid::PermissionResult::Denied){
                        auto resultHash = QtAndroid::requestPermissionsSync(QStringList({permission}));
                        if(resultHash[permission] == QtAndroid::PermissionResult::Denied)
                            return -1;
                    }
                }
        
            QQmlApplicationEngine engine;
        
            qmlRegisterType<Helper>("com.masternuts.helper", 1, 0, "Helper");
        
            const QUrl url(QStringLiteral("qrc:/main.qml"));
            QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                             &app, [url](QObject *obj, const QUrl &objUrl) {
                if (!obj && url == objUrl)
                    QCoreApplication::exit(-1);
            }, Qt::QueuedConnection);
            engine.load(url);
        
            return app.exec();
        }
        
        

        This is my main.cpp. What I'm getting is "undefined reference to 'QtAndroid::checkPermission(QString const&)'", and the same error for requestPermissionsSync.

        I tried checking the definition of these functions and they do exist in the qtandroidextras module of my Qt installation. What could possibly be wrong here?

        For extra information, I'm using Qt 5.12.3, building on Android arm64-v8a using qmake.

        I know this could be a silly error, but I'm still not so familiar with how everything in Qt works. Any help would be appreciated.

        Thanks in advance :)

        J Offline
        J Offline
        JonB
        wrote on 27 Feb 2021, 14:30 last edited by
        #3

        @GangsterV said in Error when using checkPermissions:

        What I'm getting is "undefined reference to 'QtAndroid::checkPermission(QString const&)'", and the same error for requestPermissionsSync.

        Is that an error when compiling or when linking?

        1 Reply Last reply
        0
        • G GangsterV
          27 Feb 2021, 13:52

          Hi guys,

          I'm developing an android app where I have to store some data and retrieve it when the app opens again. The problem is, I can't create a file in any place except the internal storage, but I need it in the external storage so that I can actually check the file and see what it contains.

          I could narrow this down to be a permissions problem, so I tried create some code to request for permissions at the start and checked previous threads, but I got a very unexpected error.

          #include <QGuiApplication>
          #include <QQmlApplicationEngine>
          #include "helper.h"
          #include <QtAndroidExtras/QtAndroid>
          
          int main(int argc, char *argv[])
          {
          #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
              QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          #endif
          
              QGuiApplication app(argc, argv);
          
          
              const QVector<QString> permissions({"android.permission.WRITE_EXTERNAL_STORAGE",
                                                  "android.permission.READ_EXTERNAL_STORAGE"});
          
                  for(const QString &permission : permissions){
                      auto result = QtAndroid::checkPermission(permission);
                      if(result == QtAndroid::PermissionResult::Denied){
                          auto resultHash = QtAndroid::requestPermissionsSync(QStringList({permission}));
                          if(resultHash[permission] == QtAndroid::PermissionResult::Denied)
                              return -1;
                      }
                  }
          
              QQmlApplicationEngine engine;
          
              qmlRegisterType<Helper>("com.masternuts.helper", 1, 0, "Helper");
          
              const QUrl url(QStringLiteral("qrc:/main.qml"));
              QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                               &app, [url](QObject *obj, const QUrl &objUrl) {
                  if (!obj && url == objUrl)
                      QCoreApplication::exit(-1);
              }, Qt::QueuedConnection);
              engine.load(url);
          
              return app.exec();
          }
          
          

          This is my main.cpp. What I'm getting is "undefined reference to 'QtAndroid::checkPermission(QString const&)'", and the same error for requestPermissionsSync.

          I tried checking the definition of these functions and they do exist in the qtandroidextras module of my Qt installation. What could possibly be wrong here?

          For extra information, I'm using Qt 5.12.3, building on Android arm64-v8a using qmake.

          I know this could be a silly error, but I'm still not so familiar with how everything in Qt works. Any help would be appreciated.

          Thanks in advance :)

          K Offline
          K Offline
          KroMignon
          wrote on 27 Feb 2021, 15:01 last edited by
          #4

          @GangsterV said in Error when using checkPermissions:

          For extra information, I'm using Qt 5.12.3, building on Android arm64-v8a using qmake.

          One other point, I've forgotten to ask: did you enable Android Extras in your PRO file (QT+= androidextras)?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0

          1/4

          27 Feb 2021, 13:52

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved