From 0a43b2d4fb13829ca193ef2bad6b7efaca8831e4 Mon Sep 17 00:00:00 2001 From: Rian Quinn Date: Mon, 2 Nov 2015 13:37:46 -0500 Subject: [PATCH] Fix compilation issue when GUI is disabled When QT is compiled without GUI support, the QMJson Library was not compiling correctly because it was not properly turning off support for GUI. This patch fixes that problem by explicitly telling QT to remove GUI support, and then also adds a define that can be used by the example code, and the test logic to detect a lack of GUI support, and disable it's use as well. [ISSUE]: https://github.com/QtMark/qmjson/issues/18 Signed-off-by: Rian Quinn --- example/example.pro | 13 ++++++++++++- example/main.cpp | 21 ++++++++++++++++++++- src/core/core.pro | 6 ++++++ test/test.cpp | 4 ++++ test/test.h | 14 ++++++++++++++ test/test.pro | 13 ++++++++++++- test/testgui.cpp | 3 +++ 7 files changed, 71 insertions(+), 3 deletions(-) diff --git a/example/example.pro b/example/example.pro index dd227b3..ba80201 100644 --- a/example/example.pro +++ b/example/example.pro @@ -32,8 +32,19 @@ SOURCES += main.cpp # QMJson Required #------------------------------------------------------------------------------- +!contains(QT_MODULES, gui) { + + QT -= gui + DEFINES += DISABLE_QMJSON_GUI + + LIBS += -lqmjson + +} else { + + LIBS += -lqmjson -lqmjsongui +} + CONFIG += c++11 -LIBS += -lqmjson -lqmjsongui #------------------------------------------------------------------------------- # Clean diff --git a/example/main.cpp b/example/main.cpp index 64efd21..268211e 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -19,11 +19,19 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -#include +#ifndef DISABLE_QMJSON_GUI +#include #include #include +#else + +#include +#include + +#endif + int main(int argc, char const *argv[]) { (void) argc; @@ -33,11 +41,15 @@ int main(int argc, char const *argv[]) // Setup //-------------------------------------------------------------------------- +#ifndef DISABLE_QMJSON_GUI + QMJsonValue::registerFromComplexJson("QColor", &QMJsonType::fromComplexJson); QMJsonValue::registerFromComplexJson("QPoint", &QMJsonType::fromComplexJson); QMJsonValue::registerFromComplexJson("QRect", &QMJsonType::fromComplexJson); QMJsonValue::registerFromComplexJson("QSize", &QMJsonType::fromComplexJson); +#endif + auto value1 = QMPointer(new QMJsonValue(5.5)); auto value2 = QMPointer(new QMJsonValue("Hello")); auto value3 = QMPointer(new QMJsonValue(true)); @@ -57,11 +69,15 @@ int main(int argc, char const *argv[]) tree->insert("array", array); tree->insert("object", object); +#ifndef DISABLE_QMJSON_GUI + auto complexValue1 = QMPointer(new QMJsonValue(QColor("red"))); auto complexValue2 = QMPointer(new QMJsonValue(QPoint(2, 2))); auto complexValue3 = QMPointer(new QMJsonValue(QRect(5, 5, 3, 3))); auto complexValue4 = QMPointer(new QMJsonValue(QSize(10, 10))); +#endif + //-------------------------------------------------------------------------- // Valid //-------------------------------------------------------------------------- @@ -168,6 +184,7 @@ int main(int argc, char const *argv[]) // Complex Types //-------------------------------------------------------------------------- +#ifndef DISABLE_QMJSON_GUI qDebug() << "Complex Values:"; qDebug() << complexValue1; @@ -211,5 +228,7 @@ int main(int argc, char const *argv[]) qDebug() << QMJsonValue::fromJson(complexValue4->toJson()); qDebug() << ""; +#endif + return 0; } diff --git a/src/core/core.pro b/src/core/core.pro index 5e94f5d..25eeadc 100644 --- a/src/core/core.pro +++ b/src/core/core.pro @@ -32,6 +32,12 @@ TARGET = qmjson FEATURES = ../../include/qmjsonfeatures.h write_file($$FEATURES); +!contains(QT_MODULES, gui) { + + QT -= gui + DEFINES += DISABLE_QMJSON_GUI +} + contains(QT_MODULES, dbus) { QT += dbus diff --git a/test/test.cpp b/test/test.cpp index 5f3f0de..328bda8 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -29,10 +29,14 @@ void TestJson::initTestCase(void) { qInstallMessageHandler(noMessageOutput); +#ifndef DISABLE_QMJSON_GUI + QMJsonValue::registerFromComplexJson("QColor", &QMJsonType::fromComplexJson); QMJsonValue::registerFromComplexJson("QPoint", &QMJsonType::fromComplexJson); QMJsonValue::registerFromComplexJson("QRect", &QMJsonType::fromComplexJson); QMJsonValue::registerFromComplexJson("QSize", &QMJsonType::fromComplexJson); + +#endif } void TestJson::signaled(void) diff --git a/test/test.h b/test/test.h index 237fd6a..f6bca48 100644 --- a/test/test.h +++ b/test/test.h @@ -21,9 +21,19 @@ #include +#ifndef DISABLE_QMJSON_GUI + +#include #include #include +#else + +#include +#include + +#endif + class TestJson: public QObject { Q_OBJECT @@ -103,11 +113,15 @@ private slots: virtual void QMJsonObject_custom(void); virtual void QMJsonObject_signals(void); +#ifndef DISABLE_QMJSON_GUI + virtual void QMJsonGui_qsize(void); virtual void QMJsonGui_qpoint(void); virtual void QMJsonGui_qrect(void); virtual void QMJsonGui_qcolor(void); +#endif + virtual void signaled(void); private: diff --git a/test/test.pro b/test/test.pro index e1c9889..a8d1809 100644 --- a/test/test.pro +++ b/test/test.pro @@ -38,8 +38,19 @@ SOURCES += testgui.cpp # QMJson Required #------------------------------------------------------------------------------- +!contains(QT_MODULES, gui) { + + QT -= gui + DEFINES += DISABLE_QMJSON_GUI + + LIBS += -lqmjson + +} else { + + LIBS += -lqmjson -lqmjsongui +} + CONFIG += c++11 -LIBS += -lqmjson -lqmjsongui #------------------------------------------------------------------------------- # Clean diff --git a/test/testgui.cpp b/test/testgui.cpp index 1fe61dc..896917d 100644 --- a/test/testgui.cpp +++ b/test/testgui.cpp @@ -21,6 +21,8 @@ #include +#ifndef DISABLE_QMJSON_GUI + void TestJson::QMJsonGui_qsize(void) { auto value00 = QMPointer(new QMJsonValue(QSize())); @@ -120,3 +122,4 @@ void TestJson::QMJsonGui_qcolor(void) QVERIFY(QMJsonValue::fromJson(pjson04)->to(QColor()) == color04); } +#endif