Skip to content

Commit 0a43b2d

Browse files
committed
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]: #18 Signed-off-by: Rian Quinn <[email protected]>
1 parent 8fe4e18 commit 0a43b2d

File tree

7 files changed

+71
-3
lines changed

7 files changed

+71
-3
lines changed

example/example.pro

+12-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,19 @@ SOURCES += main.cpp
3232
# QMJson Required
3333
#-------------------------------------------------------------------------------
3434

35+
!contains(QT_MODULES, gui) {
36+
37+
QT -= gui
38+
DEFINES += DISABLE_QMJSON_GUI
39+
40+
LIBS += -lqmjson
41+
42+
} else {
43+
44+
LIBS += -lqmjson -lqmjsongui
45+
}
46+
3547
CONFIG += c++11
36-
LIBS += -lqmjson -lqmjsongui
3748

3849
#-------------------------------------------------------------------------------
3950
# Clean

example/main.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919
// License along with this library; if not, write to the Free Software
2020
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2121

22-
#include <QtGui>
22+
#ifndef DISABLE_QMJSON_GUI
2323

24+
#include <QtGui>
2425
#include <qmjson.h>
2526
#include <qmjsongui.h>
2627

28+
#else
29+
30+
#include <QtCore>
31+
#include <qmjson.h>
32+
33+
#endif
34+
2735
int main(int argc, char const *argv[])
2836
{
2937
(void) argc;
@@ -33,11 +41,15 @@ int main(int argc, char const *argv[])
3341
// Setup
3442
//--------------------------------------------------------------------------
3543

44+
#ifndef DISABLE_QMJSON_GUI
45+
3646
QMJsonValue::registerFromComplexJson("QColor", &QMJsonType<QColor>::fromComplexJson);
3747
QMJsonValue::registerFromComplexJson("QPoint", &QMJsonType<QPoint>::fromComplexJson);
3848
QMJsonValue::registerFromComplexJson("QRect", &QMJsonType<QRect>::fromComplexJson);
3949
QMJsonValue::registerFromComplexJson("QSize", &QMJsonType<QSize>::fromComplexJson);
4050

51+
#endif
52+
4153
auto value1 = QMPointer<QMJsonValue>(new QMJsonValue(5.5));
4254
auto value2 = QMPointer<QMJsonValue>(new QMJsonValue("Hello"));
4355
auto value3 = QMPointer<QMJsonValue>(new QMJsonValue(true));
@@ -57,11 +69,15 @@ int main(int argc, char const *argv[])
5769
tree->insert("array", array);
5870
tree->insert("object", object);
5971

72+
#ifndef DISABLE_QMJSON_GUI
73+
6074
auto complexValue1 = QMPointer<QMJsonValue>(new QMJsonValue(QColor("red")));
6175
auto complexValue2 = QMPointer<QMJsonValue>(new QMJsonValue(QPoint(2, 2)));
6276
auto complexValue3 = QMPointer<QMJsonValue>(new QMJsonValue(QRect(5, 5, 3, 3)));
6377
auto complexValue4 = QMPointer<QMJsonValue>(new QMJsonValue(QSize(10, 10)));
6478

79+
#endif
80+
6581
//--------------------------------------------------------------------------
6682
// Valid
6783
//--------------------------------------------------------------------------
@@ -168,6 +184,7 @@ int main(int argc, char const *argv[])
168184
// Complex Types
169185
//--------------------------------------------------------------------------
170186

187+
#ifndef DISABLE_QMJSON_GUI
171188

172189
qDebug() << "Complex Values:";
173190
qDebug() << complexValue1;
@@ -211,5 +228,7 @@ int main(int argc, char const *argv[])
211228
qDebug() << QMJsonValue::fromJson(complexValue4->toJson());
212229
qDebug() << "";
213230

231+
#endif
232+
214233
return 0;
215234
}

src/core/core.pro

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ TARGET = qmjson
3232
FEATURES = ../../include/qmjsonfeatures.h
3333
write_file($$FEATURES);
3434

35+
!contains(QT_MODULES, gui) {
36+
37+
QT -= gui
38+
DEFINES += DISABLE_QMJSON_GUI
39+
}
40+
3541
contains(QT_MODULES, dbus) {
3642

3743
QT += dbus

test/test.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ void TestJson::initTestCase(void)
2929
{
3030
qInstallMessageHandler(noMessageOutput);
3131

32+
#ifndef DISABLE_QMJSON_GUI
33+
3234
QMJsonValue::registerFromComplexJson("QColor", &QMJsonType<QColor>::fromComplexJson);
3335
QMJsonValue::registerFromComplexJson("QPoint", &QMJsonType<QPoint>::fromComplexJson);
3436
QMJsonValue::registerFromComplexJson("QRect", &QMJsonType<QRect>::fromComplexJson);
3537
QMJsonValue::registerFromComplexJson("QSize", &QMJsonType<QSize>::fromComplexJson);
38+
39+
#endif
3640
}
3741

3842
void TestJson::signaled(void)

test/test.h

+14
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@
2121

2222
#include <QtTest/QtTest>
2323

24+
#ifndef DISABLE_QMJSON_GUI
25+
26+
#include <QtGui>
2427
#include <qmjson.h>
2528
#include <qmjsongui.h>
2629

30+
#else
31+
32+
#include <QtCore>
33+
#include <qmjson.h>
34+
35+
#endif
36+
2737
class TestJson: public QObject
2838
{
2939
Q_OBJECT
@@ -103,11 +113,15 @@ private slots:
103113
virtual void QMJsonObject_custom(void);
104114
virtual void QMJsonObject_signals(void);
105115

116+
#ifndef DISABLE_QMJSON_GUI
117+
106118
virtual void QMJsonGui_qsize(void);
107119
virtual void QMJsonGui_qpoint(void);
108120
virtual void QMJsonGui_qrect(void);
109121
virtual void QMJsonGui_qcolor(void);
110122

123+
#endif
124+
111125
virtual void signaled(void);
112126

113127
private:

test/test.pro

+12-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,19 @@ SOURCES += testgui.cpp
3838
# QMJson Required
3939
#-------------------------------------------------------------------------------
4040

41+
!contains(QT_MODULES, gui) {
42+
43+
QT -= gui
44+
DEFINES += DISABLE_QMJSON_GUI
45+
46+
LIBS += -lqmjson
47+
48+
} else {
49+
50+
LIBS += -lqmjson -lqmjsongui
51+
}
52+
4153
CONFIG += c++11
42-
LIBS += -lqmjson -lqmjsongui
4354

4455
#-------------------------------------------------------------------------------
4556
# Clean

test/testgui.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include <test.h>
2323

24+
#ifndef DISABLE_QMJSON_GUI
25+
2426
void TestJson::QMJsonGui_qsize(void)
2527
{
2628
auto value00 = QMPointer<QMJsonValue>(new QMJsonValue(QSize()));
@@ -120,3 +122,4 @@ void TestJson::QMJsonGui_qcolor(void)
120122
QVERIFY(QMJsonValue::fromJson(pjson04)->to<QColor>(QColor()) == color04);
121123
}
122124

125+
#endif

0 commit comments

Comments
 (0)