QT_VERSION

这个宏展开为数值形式 0xMMNNPP (MM=major, NN=minor, PP=patch) 表示Qt编译器版本。

例如: Qt编译器版本为Qt5.9.1, 则 QT_VERSION 为 0x050901

这个宏常用于条件编译,根据Qt版本不同,编译不同的代码段:

  1. #if QT_VERSION >= 0x040100
  2. QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
  3. #else
  4. QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
  5. QIcon icon(pixmap);
  6. #endif

QT_VERSION_CHECK

这个宏展开为Qt版本号的一个整数表示

  1. #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
  2. #include <QWidget>
  3. #else
  4. #include <QGUI>
  5. #endif

Q_UNUSE(name)

在函数中定义,但不使用,解决编译时报警告用。

  1. void Widget::on_imageSaved(int id, const QString &fileName)
  2. {
  3. Q_UNUSE(id);
  4. LabInfo->setText("保存为:"+ fileName);
  5. }

qDebug(const char *message…)

在debug窗体显示信息,如果编译器设置了Qt_NO_DEBUG_OUTPUT,则不输出

  1. qDebug("item in list: %d", myList.size())