Qt common global macro definition

QT_VERSION ,QT_VERSION_CHECK

// 主要用于条件编译设置,根据Qt版本不同编译不同的代码
// 我这里用的Qt版本是5.12.2,因此软件走的分支是isHighVer = false;
// 示例代码:
#if QT_VERSION >= QT_VERSION_CHECK(5,12,2) 
    isHighVer = true;
#else
    isHighVer = false;
#endif

QT_VERSION_STR

This macro expands to a string of the Qt version number, such as "5.9.0"

// 打印当前Qt版本的字符串
qDebug() << QT_VERSION_STR << endl;

Q_BYTE_ORDER、Q_BIG_ENDIAN、Q_LITTLE_ENDIAN

Q_BYTE_ORDER indicates the byte order used by the data in the system memory;
Q_BIG_ENDIAN indicates the big-endian byte order;
Q_LITTLE_ENDIAN indicates the little-endian byte order.
These macros are only used when it is necessary to determine the byte order of the system. Examples of usage are as follows:

// 检测系统是否为小端
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN  // 我的这个平台是小端的
    qDebug() << "Q_LITTLE_ENDIAN" << endl;
#else

#endif

QT_NO_DEBUG_OUTPUT

Add the following code in the pro file, all QDebug in the software will be invalid

# 禁用所有QDebug打印
DEFINES += QT_NO_DEBUG_OUTPUT

Q_FUNC_INFO

The class and parameter information of the function.

// 打印函数所属类和参数信息
qDebug() << Q_FUNC_INFO <<this is a debug example”;

Q_UNUSED(valuename)

For unused variables in functions, tell the compiler that this variable does not need to warn. In addition, you can also add the following code to the pro file to block unused alarms:

void MainWindow::on_imageSaved(int id, const QString &fileName)
{
    
    
   Q_UNUSED(id);
   LabInfo->setText("图片保存为: " + fileName);
}

# 屏蔽未使用的告警
QMAKE_CXXFLAGS += -Wno-unused-parameter

Q_DECL_OVERRIDE

In a class definition, it is used to overload a virtual function, for example, to overload the virtual function paintEvent() in a certain class, it can be defined as follows:

void  paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;

After using the Q_DECL_OVERRIDE macro, if the overloaded virtual function does not perform any overloading operation, the compiler will report an error.

Q_DECL_FINAL

Used to define a virtual function as the final level and can no longer be overloaded, or to define a class that can no longer be inherited.

class QPushButton Q_DECL_FINAL {
    
      // QPushButton 不能再被继承
	//...
};

Q_SIGNAL

A function can be designated as a signal function without the signals keyword.

class A :  public QObject
{
    
    
Q_OBJECT

Q_SIGNALS:
	void sigTest(QPoint point);
}

Q_SLOT

A function can be designated as a slot function without the slots keyword.

class B :  public QObject
{
    
    
Q_OBJECT
     
private Q_SLOTS:
	void slotTest(QPoint point);
}

Guess you like

Origin blog.csdn.net/houxian1103/article/details/131623575