zoukankan      html  css  js  c++  java
  • Qt一些方便易用的小技巧

    延迟给自己发信号执行操作

    //延迟4500毫秒, 改变Status的值.
    QTimer::singleShot(4500, this, [&](){
                        this->Status = 0;
                    });
    

    条件编译

    #define           定义宏
    #undef            取消宏
    #if               编译预处理中的条件命令(可用来注释代码(#if 0)则作用域的代码不执行)
    #ifdef            判断某个宏是否被定义, 若有定义则执行作用域内的代码. 
    #ifndef           与#ifdef相反, 若未被定义则执行作用域内的代码.
    #elif             若#if, #ifdef, #ifndef或前面的#elif条件不满足, 则执行#elif之后的语句, 相当于C语法中的else if
    #else             与#if, #ifdef, #ifndef对应, 若这些条件不满足, 则执行#else之后的语句, 相当于C语法中的else
    #endif            #if, #ifdef, #ifndef条件编译的结束标志.
    defined          与#if, #elif配合使用, 判断某个宏是否被定义
    

    虚函数语法检查

    //在虚函数定义后面加上"Q_DECL_OVERRIDE"宏, 会自动对虚函数进行"override"检查, 如果不是"override"则会报语法错误.
    void run() Q_DECL_OVERRIDE;
    

    显式禁用拷贝构造

    • 有时, 我们不需要对象的副本, 可以禁用拷贝构造. 使用DISALLOW_COPY_AND_ASSIGN宏, 可以实现该目的.
    • 查询发现: DISALLOW_COPY_AND_ASSIGN宏的定义如下:
    // A macro to disallow the copy constructor and operator= functions 
    // This should be used in the priavte:declarations for a class
    #define    DISALLOW_COPY_AND_ASSIGN(TypeName) 
        TypeName(const TypeName&);                
        TypeName& operator=(const TypeName&)
    
    • 使用方法如下(原理: 将拷贝构造声明为私有, 但不实现):
    class Test {
    public:
        Test(int t);
        ~Test();
    private:
        DISALLOW_COPY_AND_ASSIGN(Test);
    };
    

    Qt/QML界面整体缩放

    //在QApp创建之前设置该参数, 这里缩放到0.5倍大小.
    qputenv("QT_SCALE_FACTOR", "0.5");
    
  • 相关阅读:
    6. Flask请求和响应
    5. Flask模板
    FW:Software Testing
    What is the difference between modified duration, effective duration and duration?
    How to push master to QA branch in GIT
    FTPS Firewall
    Query performance optimization of Vertica
    (Forward)5 Public Speaking Tips That'll Prepare You for Any Interview
    (转)The remote certificate is invalid according to the validation procedure
    Change
  • 原文地址:https://www.cnblogs.com/linkyip/p/11526375.html
Copyright © 2011-2022 走看看