如何在Qt创建者中安装QJson(Qt 4.8.6)

时间:2014-10-06 10:33:50

标签: c++ json linux qt qt4

我想在Qt创建者中使用QJson。我使用的是Qt 4.8.6,所以在QtCore中没有像Qt5那样的Json lib。

我去过sourceforge网站:http://qjson.sourceforge.net/build/,它说我应该使用包管理工具安装qjson。所以我使用apt-get install安装了 libqjson0,libqjson-dev,libqjson-dbg和libqjson0-dbg 包。

我创建了一个新项目并将官方网站的示例复制到其中。我修改了我的.pro文件,我添加了一个外部库( libqjson.so ),因此Qt创建者自动将以下代码添加到.pro文件中:

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../usr/lib/x86_64-linux-gnu/release/ -lqjson else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../usr/lib/x86_64-linux-gnu/debug/ -lqjson else:unix: LIBS += -L$$PWD/../../../../../../usr/lib/x86_64-linux-gnu/ -lqjson INCLUDEPATH += $$PWD/../../../../../../usr/lib/x86_64-linux-gnu DEPENDPATH += $$PWD/../../../../../../usr/lib/x86_64-linux-gnu

libqjson.so 文件位于 x86_64-linux-gnu 路径中。 我还添加了一行包括parse.h文件和其他文件: INCLUDEPATH += $$PWD/../../../../../../usr/include/qjson

之后,我可以包括,但我不能在我的代码中使用像 toMap(),toString()这样的函数...

我认为我的安装过程一定有问题。这是我的代码:

int main(int argc, char *argv[])
{
    QJson::Parser parser;
    bool ok;

    QString json;
    json = "{\"encoding\" : \"UTF-8\",\"plug-ins\": [\"python\",\"c++\", \"ruby\"],\"indent\":{\"length\": 3,\"use_space\":true}}";

    QVariantMap result = parser.parse(json, &ok).toMap();
    if (!ok) {
      qFatal("An error occurred during parsing");
      exit (1);
    }

    qDebug() << "encoding:" << result["encoding"].toString();
    qDebug() << "plugins:";

    foreach (QVariant plugin, result["plug-ins"].toList()) {
      qDebug() << "\t-" << plugin.toString();
    }

    QVariantMap nestedMap = result["indent"].toMap();
    qDebug() << "length:" << nestedMap["length"].toInt();
    qDebug() << "use_space:" << nestedMap["use_space"].toBool();
    QApplication a(argc, argv);
    QJsons w;
    w.show();

    return a.exec();
}

这是我的错误信息:

08:40:53:为项目QJson运行步骤...... 08:40:53:配置不变,跳过qmake步骤。 08:40:53:开始:&#34; / usr / bin / make&#34; /usr/local/Trolltech/Qt-4.8.6/bin/qmake -spec /usr/local/Trolltech/Qt-4.8.6/mkspecs/linux-g++ CONFIG + = debug -o Makefile ../QJson/QJson.pro g ++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I / usr / local / Trolltech / Qt-4.8.6 / mkspecs / linux-g ++ -I ../ QJson -I / usr / local / Trolltech / Qt-4.8.6 / include / QtCore -I / usr / local / Trolltech / Qt-4.8.6 / include / QtGui -I / usr / local / Trolltech / Qt-4.8.6 / include -I / home / cecaadmin / GRT / QtProjects / TranferFileDemo / QJson /../../../ usr / include / qjson -I / usr / include / qjson -I。 -I ../ QJson -I。 -o main.o ../ QJson / main.cpp

../ QJson / main.cpp:在函数&#39; int main(int,char **)&#39;:

../ QJson / main.cpp:13:48:错误:没有匹配函数来调用

&#39; QJson :: Parser :: parse(QString&amp;,bool *)&#39;      QVariantMap结果= parser.parse(json,&amp; ok).toMap();                                                 ^ ../QJson/main.cpp:13:48:注意:候选人是: 在../QJson/main.cpp:4:0中包含的文件中: /usr/include/qjson/parser.h:51:16:注意:QVariant QJson :: Parser :: parse(QIODevice *,bool *)        QVariant解析(QIODevice * io,bool * ok = 0);                 ^ /usr/include/qjson/parser.h:51:16:注意:来自&#39; QString&#39;的参数1没有已知的转换。到&#39; QIODevice *&#39; /usr/include/qjson/parser.h:61:16:注意:QVariant QJson :: Parser :: parse(const QByteArray&amp;,bool *)        QVariant解析(const QByteArray&amp; jsonData,bool * ok = 0);                 ^ /usr/include/qjson/parser.h:61:16:注意:来自&#39; QString&#39;的参数1没有已知的转换。到了&#39; const QByteArray&amp;&#39; ../QJson/main.cpp:19:12:错误:无效使用不完整类型&#39;类QDebug&#39;      qDebug()&lt;&lt; &#34;编码:&#34; &LT;&LT;结果[&#34;编码&#34]。的toString();             ^ 在/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qnamespace.h:45:0中包含的文件中,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qobjectdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwindowdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwidget.h:46,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/QWidget:1,                  来自../QJson/qjsons.h:4,                  来自../ QJson / main.cpp:1:

/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qglobal.h:1793:7:错误:&#39;班级QDebug&#39;  QDebug班;        ^

../ QJson / main.cpp:20:12:错误:无效使用不完整类型&#39;类QDebug&#39;      qDebug()&lt;&lt; &#34;插件:&#34 ;;             ^ 在/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qnamespace.h:45:0中包含的文件中,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qobjectdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwindowdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwidget.h:46,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/QWidget:1,                  来自../QJson/qjsons.h:4,                  来自../ QJson / main.cpp:1:

/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qglobal.h:1793:7:错误:&#39;班级QDebug&#39;  QDebug班;        ^

../ QJson / main.cpp:23:14:错误:无效使用不完整类型&#39;类QDebug&#39;        qDebug()&lt;&lt; &#34; \吨 - &#34; &LT;&LT; plugin.toString();               ^ 在/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qnamespace.h:45:0中包含的文件中,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qobjectdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwindowdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwidget.h:46,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/QWidget:1,                  来自../QJson/qjsons.h:4,                  来自../ QJson / main.cpp:1:

/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qglobal.h:1793:7:错误:&#39;班级QDebug&#39;  QDebug班;        ^

../ QJson / main.cpp:27:12:错误:无效使用不完整类型&#39;类QDebug&#39;      qDebug()&lt;&lt; &#34;长度:&#34; &LT;&LT; nestedMap [&#34;长度&#34]。toInt();             ^ 在/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qnamespace.h:45:0中包含的文件中,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qobjectdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwindowdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwidget.h:46,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/QWidget:1,                  来自../QJson/qjsons.h:4,                  来自../ QJson / main.cpp:1:

/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qglobal.h:1793:7:错误:&#39;班级QDebug&#39;  QDebug班;        ^

../ QJson / main.cpp:28:12:错误:无效使用不完整类型&#39;类QDebug&#39;      qDebug()&lt;&lt; &#34; use_space:&#34; &LT;&LT; nestedMap [&#34; use_space&#34]。toBool();             ^ 在/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qnamespace.h:45:0中包含的文件中,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qobjectdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwindowdefs.h:45,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/qwidget.h:46,                  来自/usr/local/Trolltech/Qt-4.8.6/include/QtGui/QWidget:1,                  来自../QJson/qjsons.h:4,                  来自../ QJson / main.cpp:1:

/usr/local/Trolltech/Qt-4.8.6/include/QtCore/qglobal.h:1793:7:错误:&#39;班级QDebug&#39;  QDebug班;        ^ /usr/local/Trolltech/Qt-4.8.6/include/QtCore/qglobal.h:在全球范围内: /usr/local/Trolltech/Qt-4.8.6/include/QtCore/qglobal.h:1796:29:警告:内联函数&#39; QDebug qDebug()&#39;已使用但未定义[默认启用]  Q_CORE_EXPORT_INLINE QDebug qDebug();                              ^ make:*** [main.o]错误1 08:40:54:流程&#34; / usr / bin / make&#34;退出代码2。 构建/部署项目QJson时出错(工具包:桌面) 执行步骤&#39;制作&#39;

0 个答案:

没有答案