Qt notes - official documents defined globally (c) Macros Macros

Series Summary:

Qt notes - official documents global definitions (a) Types of data types: https://blog.csdn.net/qq_41895747/article/details/104084660

Qt notes - official documents defined globally (b) Functions Function: https://blog.csdn.net/qq_41895747/article/details/104091158

Qt notes - official documents defined globally (c) Macros Macro: https://blog.csdn.net/qq_41895747/article/details/104196369

Part III dragged on for a long time, mainly too much, I did not used a lot, or pick commonly used to write about


There are hundreds of built-in QtGobal the global definition, probably more than twenty commonly divided into Types Data Types, Functions function, Macros macros

Documents Address: https://doc.qt.io/qt-5/qtglobal.html#QFunctionPointer-typedef


table of Contents

Series Summary:

QT_VERSION

QT_VERSION_CHECK

QT_VERSION_STR

qDebug(const char *message, ...)

Q_DECL_OVERRIDE

Q_UNUSED(name)

Q_DECL_FINAL


QT_VERSION

Version information in numerical form, such as in the Qt 4.1.2, QT_VERSION macro expands to 0x040102.

QT_VERSION_CHECK

Integer version information. Format: 0xMMNNPP (MM = major, NN = minor, PP = patch)

QT_VERSION_STR

A string of version information. For example, "4.1.2"

qDebug(const char *message...)

When debugging, the format:

qDebug("Items in list: %d", myList.size());

If you include <QtDebug> after, you can also use this:

qDebug() << "已经执行到这一步" << endl;

Q_DECL_OVERRIDE

Overload for a virtual function, virtual function if overloaded without any operation, the compiler will complain!

Commonly used in the self-defined libraries and plug-ins when

protected:
    void    paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

Q_UNUSED(name)

Is not used to define the parameters of the function in vivo can be eliminated compiler warnings within the function.

example:

void MainWindow::on_currentChanged(const QModelIndex &current, const QModelIndex &previous){
    //定义不在函数体中使用过的参数,可以消除编译器产生的警告
//    Q_UNUSED(current);
//    Q_UNUSED(previous);
    //更新状态,将保存键和取消键设置为可用状态
    ui->SaveAction->setEnabled(true);
    ui->CancleAction->setEnabled(true);
}

current and previous not used in the body of the function, the compiler will issue a warning:

Plus you can post:

void MainWindow::on_currentChanged(const QModelIndex &current, const QModelIndex &previous){
    //定义不在函数体中使用过的参数,可以消除编译器产生的警告
    Q_UNUSED(current);
    Q_UNUSED(previous);
    //更新状态,将保存键和取消键设置为可用状态
    ui->SaveAction->setEnabled(true);
    ui->CancleAction->setEnabled(true);
}

Q_DECL_FINAL

The definition of a virtual function of the final level, can not be overloaded; or definition of a class can not be overloaded.

If support C ++ 11, instead of directly with the final!

Virtual functions:

 // more-derived classes no longer permitted to override this:
    virtual void MyWidget::paintEvent(QPaintEvent*) final;

class:

 class QRect final { // cannot be derived from
        // ...
    };

For example some commonly Q_OBJECT the like, not <QtGlobal> is not repeated

Published 287 original articles · won praise 297 · views 120 000 +

Guess you like

Origin blog.csdn.net/qq_41895747/article/details/104196369