zoukankan      html  css  js  c++  java
  • 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);
    }
    

      

  • 相关阅读:
    批处理系统中采用的调度算法
    机器学习(周志华西瓜书)参考答案总目录
    机器学习(周志华西瓜书)参考答案总目录
    主题模型LDA及在推荐系统中的应用
    常见的六大聚类算法
    大数据学习笔记·城市计算(1)
    数据预处理之数据规约(Data Reduction)
    高维数据稀疏表示-什么是字典学习(过完备词典)
    dev gridview columns代码管理
    mysql常用命令
  • 原文地址:https://www.cnblogs.com/sankye/p/14541310.html
Copyright © 2011-2022 走看看