zoukankan      html  css  js  c++  java
  • 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>也是可以的,像它这样做,好像是可以降低各个文件编译时的关联度,不会在改动了一下部分类的时候,引 发其他大量文件的重新编译,在做小工程的时候没什么区别,但是做大了,编译一次需要好几个小时的时候,这样做的优势就显现出来了

  • 相关阅读:
    seo课程教程笔记公布【网络转载】
    建立一个windows服务(可用于实现计划任务,事件监控..) .NET
    运行界面上,实现随意拖动控件 .NET
    定时关机的小程序 .NET
    服务 安装与删除 .NET
    模拟鼠标/键盘 .NET实现
    Google Code 创建开源项目
    一个批处理文件 启动停止服务.bat
    提升搜索引擎中网站排名的工具[持续更新中..]
    DateTime.Now.ToString()用法
  • 原文地址:https://www.cnblogs.com/wiessharling/p/2865026.html
Copyright © 2011-2022 走看看