Skip to content

Instantly share code, notes, and snippets.

@kheaactua
Created January 15, 2018 19:33
Show Gist options
  • Save kheaactua/e2b13981b941fde6fd4188ed309050fc to your computer and use it in GitHub Desktop.
Save kheaactua/e2b13981b941fde6fd4188ed309050fc to your computer and use it in GitHub Desktop.
Example of Q_FLAG_NS not functioning
#include "App.h"
#ifndef APP_H_BYLS6KFN
#define APP_H_BYLS6KFN
#include <QObject>
namespace App {
Q_NAMESPACE
enum class ComponentRequirementState
{
NotRequired = 0x0,
RequiredForStartup = 0x01,
AlwaysRequired = 0x02,
testme = NotRequired | AlwaysRequired
};
Q_FLAG_NS(ComponentRequirementState)
}
#endif /* end of include guard: APP_H_BYLS6KFN */
/* vim: set ts=4 sw=4 sts=4 expandtab ffs=unix,dos : */
project(appex)
cmake_minimum_required(VERSION 3.0)
set(Qt_VERSION_RELEASE 5 CACHE STRING "Qt release version")
set(Qt_VERSION_MAJOR 9 CACHE STRING "Qt major version")
set(Qt_VERSION_MINOR 3 CACHE STRING "Qt minor version")
set(Qt_VERSION ${Qt_VERSION_RELEASE}.${Qt_VERSION_MAJOR}.${Qt_VERSION_MINOR})
set(CMAKE_CXX_FLAGS "-std=c++11")
# Guess at where Qt can be found.
find_path(Qt_DIR
NAME lib/cmake/Qt5/Qt5Config.cmake
PATHS
/opt/Qt${Qt_VERSION}/${Qt_VERSION}/gcc_64
/opt/Qt${Qt_VERSION}/${Qt_VERSION_RELEASE}.${Qt_VERSION_MAJOR}/gcc_64
DOC "Qt's ${COMPILER_ARCH} directory"
NO_DEFAULT_PATH
)
message("Using Qt Directory: ${Qt_DIR}")
list(APPEND Qt_COMPONENTS Core)
foreach(pkg IN ITEMS ${Qt_COMPONENTS})
# Qt_DEPS are our link targets.
list(APPEND Qt_DEPS Qt${Qt_VERSION_RELEASE}::${pkg})
endforeach()
unset(pkg_name)
find_package(
Qt${Qt_VERSION_RELEASE} REQUIRED
COMPONENTS ${Qt_COMPONENTS}
PATHS ${Qt_DIR}/lib/cmake/Qt${Qt_VERSION_RELEASE}
)
add_executable(app main.cpp App.h App.cpp)
target_link_libraries(app
${Qt_DEPS}
)
# vim: ts=4 sw=4 sts=0 noet ft=cmake ffs=unix,dos :
#include <iostream>
#include <QtCore>
#include "App.h"
auto main(int argc, char *argv[]) -> int
{
QCoreApplication app(argc, argv);
app.setApplicationName("app");
auto r = App::ComponentRequirementState::NotRequired;
r = r | App::ComponentRequirementState::AlwaysRequired;
std::cout << "r = " << static_cast<unsigned int>(r) << std::endl;
return app.exec();
}
/* vim: set ts=4 sw=4 sts=4 expandtab ffs=unix,dos : */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment