Ошибка: C2039: указатель: не является членом QJsonObject::iterator

У меня странная ошибка при попытке использовать 'QJsonObject::iterator' с MSVC2013.

У меня есть следующий пример:

#include <QCoreApplication>
#include <QJsonObject>
#include <QDebug>
#include <algorithm>

void processValue(QJsonValue value) {
    qDebug() << value.toString();
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QJsonObject jsonObject;
    jsonObject.insert("a", "A");
    jsonObject.insert("b", "B");
    jsonObject.insert("c", "C");
    jsonObject.insert("d", "D");
    jsonObject.insert("e", "E");

    std::for_each (jsonObject.begin(), jsonObject.end(), processValue);

    return a.exec();
}

Этот код компилируется и работает, как ожидается, с MSVC2008 (кросс-компиляция в WinCE) и MinGW, но не с MSVC2013. Во всех случаях я использую Qt 5.5.1.

Сообщение об ошибке:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xutility(375) : error C2039: 'pointer' : is not a member of 'QJsonObject::iterator'
        c:\qt\qt5.5.1msvc\5.5\msvc2013\include\qtcore\qjsonobject.h(96) : see declaration of 'QJsonObject::iterator'
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xutility(584) : see reference to class template instantiation 'std::iterator_traits<_InIt>' being compiled
        with
        [
            _InIt=QJsonObject::iterator
        ]
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\algorithm(31) : see reference to function template instantiation 'void std::_Debug_range<_InIt>(_InIt,_InIt,std::_Dbfile_t,std::_Dbline_t)' being compiled
        with
        [
            _InIt=QJsonObject::iterator
        ]
        ..\QJsonObjectIteratorIssue\main.cpp(21) : see reference to function template instantiation '_Fn1 std::for_each<QJsonObject::iterator,void(__cdecl *)(QJsonValue)>(_InIt,_InIt,_Fn1)' being compiled
        with
        [
            _Fn1=void (__cdecl *)(QJsonValue)
,            _InIt=QJsonObject::iterator
        ]
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xutility(375) : error C2146: syntax error : missing ';' before identifier 'pointer'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xutility(375) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xutility(375) : error C2602: 'std::iterator_traits<_InIt>::pointer' is not a member of a base class of 'std::iterator_traits<_InIt>'
        with
        [
            _InIt=QJsonObject::iterator
        ]
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xutility(375) : see declaration of 'std::iterator_traits<_InIt>::pointer'
        with
        [
            _InIt=QJsonObject::iterator
        ]
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xutility(375) : error C2868: 'std::iterator_traits<_InIt>::pointer' : illegal syntax for using-declaration; expected qualified-name
        with
        [
            _InIt=QJsonObject::iterator
        ]

Я что-то не так делаю, что случайно сработало на двух других компиляторах?

1 ответ

Решение

Используйте 5.6 или сделайте бэкпорт это: https://code.qt.io/cgit/qt/qtbase.git/commit/?id=4a318a61824216ac499ff8b0b0c55dea90501005

QJsonObject::(const_) итератор: добавить указатель typedef

В противном случае они не могут использоваться с алгоритмами std:: или чем-то еще, что требует iterator_traits.

Другие вопросы по тегам