• QT工程下安卓与win程序切换编译设置


    安卓下的代码在MinGW下调试会从出错

    .pro文件后面添加
    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {

    QT += androidextras
    }

    cpp文件中添加
    #ifdef Q_OS_ANDROID
        #include<QtAndroid>  
    #endif


    读写权限
    bool requestReadPermission() {
    #ifdef Q_OS_ANDROID
        QtAndroid::PermissionResult r = QtAndroid::checkPermission("android.permission.READ_EXTERNAL_STORAGE");
       if(r == QtAndroid::PermissionResult::Denied) {
          //   QMessageBox::information(0,"requestWritePermission22222","PermissionResult::Denied");
            QtAndroid::requestPermissionsSync( QStringList() << "android.permission.READ_EXTERNAL_STORAGE" );
            r = QtAndroid::checkPermission("android.permission.READ_EXTERNAL_STORAGE");
            if(r == QtAndroid::PermissionResult::Denied) {
                 return false;
            }
       }
    #endif
       return true;
    }
    bool requestWritePermission() {
    #ifdef Q_OS_ANDROID
        QtAndroid::PermissionResult r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
        if(r == QtAndroid::PermissionResult::Denied) {
          //  QMessageBox::information(0,"requestWritePermission","PermissionResult::Denied");
            QtAndroid::requestPermissionsSync( QStringList() << "android.permission.WRITE_EXTERNAL_STORAGE" );
            r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
            if(r == QtAndroid::PermissionResult::Denied) {
                 return false;
            }
       }
       return true;
    #endif
    }
    

      


    我的读写函数
    void ReadMyData()
    {
        requestReadPermission();
        FILE   *ffp;
    #ifdef Q_OS_ANDROID
        if((ffp=fopen((const char *)"/sdcard/s_v.quo","rb"))==NULL)
    #else
        if((ffp=fopen((const char *)"d:\s_v.quo","rb"))==NULL)
    #endif
            return ;
    
        fseek(ffp,0,SEEK_SET);    
        fread(&m_save,sizeof(Def_Save),1,ffp);
        if(m_save.myunit<0||m_save.myunit>3)
            m_save.myunit=0;
        fclose(ffp);
    }
    void    SaveMyData()
    {   FILE   *ffp; 
        requestWritePermission();
    #ifdef Q_OS_ANDROID
        if((ffp=fopen((const char *)"/sdcard/s_v.quo","wb+"))==NULL)
    #else
        if((ffp=fopen((const char *)"d:\s_v.quo","wb+"))==NULL)
    #endif
         {
          //  fclose(ffp);
             return ;
          //  exit(1);
         }
        fseek(ffp,0,SEEK_SET);
        fwrite(&m_save,sizeof(Def_Save),1,ffp);
      //  qDebug()<<m_save.p_no;
        fclose(ffp);
    }
    

      

  • 相关阅读:
    Java找N个数中最小的K个数,PriorityQueue和Arrays.sort()两种实现方法
    POJ 1661 Help Jimmy(C)动态规划
    LeetCode第8场双周赛(Java)
    Eclipse访问外部网站(比如:CSDN首页)
    LeetCode第151场周赛(Java)
    LeetCode第152场周赛(Java)
    Eclipse Block Selection(块选择)快捷键 Alt + Shift + A
    PAT(B) 1090 危险品装箱(Java)
    PAT(B) 1050 螺旋矩阵(Java:24分)
    PAT(B) 1045 快速排序(C)
  • 原文地址:https://www.cnblogs.com/sankye/p/14541310.html
Copyright © 2020-2023  润新知