LoginSignup
4
1

More than 5 years have passed since last update.

【Qt】Q_NULLPTRとは何者なのか

Last updated at Posted at 2018-01-20

Qtのサンプルコードなどで特に説明なしで使われているQ_NULLPTR。
公式のドキュメントでも説明が見つけられない。一体何者なんだ。

qtbase/src/corelib/global/qcompilerdetection.h

/*
 * C++11 keywords and expressions
 */
#ifdef Q_COMPILER_NULLPTR
# define Q_NULLPTR         nullptr
#else
# define Q_NULLPTR         NULL
#endif

ふむ、Q_COMPILER_NULLPTRが定義されていれば、nullptr、定義されていなければNULLになると。
Q_COMPILER_NULLPTRとは?

#    if __has_feature(cxx_nullptr)
#      define Q_COMPILER_NULLPTR
#    endif

ということで、どうやらコンパイラがc++11対応かどうかで、nullptrかNULLかを切り替えてくれる模様。
古いコンパイラに持って行ってもコンパイルできるので、Qtでアプリ作る上では、とりあえずQ_NULLPTRを使えば良さそう。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1