zoukankan      html  css  js  c++  java
  • Qt通用方法及类库1

    函数名

    //桌面宽度高度
    static int deskWidth();
    static int deskHeight();
    
    //程序文件名称+当前所在路径
    static QString appName();
    static QString appPath();
    
    //初始化随机数种子
    static void initRand();
    

    函数体

    int QUIHelper::deskWidth()
    {
        //没有必要每次都获取,只有当变量为空时才去获取一次
        static int width = 0;
        if (width == 0) {
            width = qApp->desktop()->availableGeometry().width();
        }
    
        return width;
    }
    
    int QUIHelper::deskHeight()
    {
        //没有必要每次都获取,只有当变量为空时才去获取一次
        static int height = 0;
        if (height == 0) {
            height = qApp->desktop()->availableGeometry().height();
        }
    
        return height;
    }
    
    QString QUIHelper::appName()
    {
        //没有必要每次都获取,只有当变量为空时才去获取一次
        static QString name;
        if (name.isEmpty()) {
            name = qApp->applicationFilePath();
            QStringList list = name.split("/");
            name = list.at(list.count() - 1).split(".").at(0);
        }
    
        return name;
    }
    
    QString QUIHelper::appPath()
    {
    #ifdef Q_OS_ANDROID
        return QString("/sdcard/Android/%1").arg(appName());
    #else
        return qApp->applicationDirPath();
    #endif
    }
    
    void QUIHelper::initRand()
    {
        //初始化随机数种子
        QTime t = QTime::currentTime();
        qsrand(t.msec() + t.second() * 1000);
    }
    
  • 相关阅读:
    C#读取EXCEL中数字无法读取的方法
    学习Wml
    sqlserver.exe进程占cpu100%
    windows phone mango 页面跳转事件顺序
    Windows 8 系列(一):win 8 简介
    windows phone 小应用与随机算法的感悟
    文件下载
    html 表格固定宽度
    excel 导入科学计数法
    word 排版
  • 原文地址:https://www.cnblogs.com/feiyangqingyun/p/12732070.html
Copyright © 2011-2022 走看看