• Qt 计算器 学习


    1. 可以在别的源代码文件实现头文件中定义的函数;例如:

        两个头文件:button.h, Calculator.h 两个源代码文件:button.cpp,Calculator.cpp

        可以在Calculator.cpp中实现button.h中定义的函数。

    2. 判断是哪个按钮按下了:

        Button*clickedButton=qobject_cast<Button*>(sender());

    3. qobject_cast

       T qobject_cast(QObject*object)

        Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns 0. If object is 0 then it will also return 0.

         The class T must inherit (directly or indirectly) QObject and be declared with the Q_OBJECT macro. A class is considered to inherit itself.

         Example:

    QObject *obj = new QTimer;          // QTimer inherits QObject
    
    QTimer *timer = qobject_cast<QTimer *>(obj);
    // timer == (QObject *)obj
    
    QAbstractButton *button = qobject_cast<QAbstractButton *>(obj);
    // button == 0

    4. QString  将一个字符串放到另一字符串的前面

    QString & QString::prepend(const QString & str)

    QString x = "ship";
    QString y = "air";
    x.prepend(y);
    // x == "airship"

    5. Qt头文件中的QT_BEGIN_NAMESPACE

    QT_BEGIN_NAMESPACE
    class QAction;
    class QCheckBox;
    class QComboBox;
    class QGroupBox;
    class QLabel;
    class QLineEdit;
    class QMenu;
    class QPushButton;
    class QSpinBox;
    class QTextEdit;
    QT_END_NAMESPACE
    //code end
    
    
    class QAction;
    class QCheckBox;


    是因为在头文件里面只有这些类的指针申明,并没有真正实例化,在这个头文件对应的cpp文件里面应该会
    #include <QAction>
    #include <QCheckBox>
    ...
    在cpp文件里面才会正真实例化这些类。
    其 实直接在头文件里面#include <QAction> #include<QCheckBox>也是可以的,像它这样做,好像是可以降低各个文件编译时的关联度,不会在改动了一下部分类的时候,引 发其他大量文件的重新编译,在做小工程的时候没什么区别,但是做大了,编译一次需要好几个小时的时候,这样做的优势就显现出来了

  • 相关阅读:
    poj2411
    poj2403
    poj2479
    poj2593
    跟着B站UP主小姐姐去华为坂田基地采访扫地僧
    云小课 | 不小心删除了数据库,除了跑路还能咋办?
    GaussDB(for MySQL)如何在存储架构设计上做到高可靠、高可用
    华为侯金龙:打造行业智能体,共建全场景智慧
    华为轮值董事长郭平2020全联接大会主题演讲:永远面向阳光,阴影甩在身后
    【API进阶之路】太秃然了,老板要我一周内检测并导入一万个小时的视频
  • 原文地址:https://www.cnblogs.com/wiessharling/p/2865026.html
Copyright © 2020-2023  润新知