Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Qt Qt Assert

 

A version of assert one can use in a Qt Creator console application

 

#ifndef BILDERBIKKEL_QT_ASSERT_H
#define BILDERBIKKEL_QT_ASSERT_H

//From http://www.richelbilderbeek.nl/CppQtAssert.htm
#ifdef NDEBUG
  #define Assert(x) ((void)0)
#else
  #include <iostream>
  #include <stdexcept>

  #define Assert(x)                      \
  if (!(x))                             \
  {                                      \
    std::cout                            \
      << "ERROR!! Assertion "            \
      <<  std::string (#x)               \
      <<  " failed\n on line "           \
      <<  (__LINE__)                     \
      <<  "\n in file "                  \
      <<  __FILE__                       \
      << std::endl;                      \
      throw std::logic_error(            \
        "Assertion failed");             \
  }
  }
#endif

#endif // BILDERBIKKEL_QT_ASSERT_H

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict