C2039 qt ошибка

I’m having a weird error when trying to use ‘QJsonObject::iterator’ with MSVC2013.

I have the following example:

#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();
}

This code compiles and works as expected with MSVC2008 (cross-compiling to WinCE) and MinGW, but not with MSVC2013. In all cases, I’m using Qt 5.5.1.

The error message is:

C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(375) : error C2039: 'pointer' : is not a member of 'QJsonObject::iterator'
        c:qtqt5.5.1msvc5.5msvc2013includeqtcoreqjsonobject.h(96) : see declaration of 'QJsonObject::iterator'
        C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(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.0VCINCLUDEalgorithm(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
        ]
        ..QJsonObjectIteratorIssuemain.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.0VCINCLUDExutility(375) : error C2146: syntax error : missing ';' before identifier 'pointer'
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(375) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(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.0VCINCLUDExutility(375) : see declaration of 'std::iterator_traits<_InIt>::pointer'
        with
        [
            _InIt=QJsonObject::iterator
        ]
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(375) : error C2868: 'std::iterator_traits<_InIt>::pointer' : illegal syntax for using-declaration; expected qualified-name
        with
        [
            _InIt=QJsonObject::iterator
        ]

Am I doing anything wrong here, that just happen to work by chance on the 2 other compilers?

SkillKota

0 / 0 / 0

Регистрация: 23.11.2015

Сообщений: 13

1

09.04.2017, 18:22. Показов 4880. Ответов 9

Метки нет (Все метки)


Студворк — интернет-сервис помощи студентам

Есть mainwindow и chat.
При нажатии кнопки должно происходить переход ко второму окну.
Выходят 2 ошибки:
chat.cpp:10: ошибка: C2039: Show: не является членом «chat»
main.cpp:15: ошибка: C3861: connect: идентификатор не найден
Помогите пожалуйста
Вот main.cpp

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "mainwindow.h"
#include<iostream>
#include <QApplication>
#include <QPushButton>
#include "chat.h"
//using namespace QObject;
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    chat cht;
    QPushButton enter;
    w.show();
    enter.show();
    connect(&enter,SIGNAL(clicked()),&cht,SLOT(chtShw()));
    return a.exec();
}

mainwindow.cpp

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}
 
MainWindow::~MainWindow()
{
    delete ui;
}

chat.cpp

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
#include "chat.h"
#include "mainwindow.h"
chat::chat(QObject *parent) : QObject(parent)
{
 
}
void chat::chtShw(){
    //chat.show();
    chat* frm = new chat();
    frm->Show();
}

mainwindow.h

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
private:
    Ui::MainWindow *ui;
};
 
#endif // MAINWINDOW_H

chat.h

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef CHAT_H
#define CHAT_H
 
#include <QObject>
class chat : public QObject
{
    Q_OBJECT
public:
    explicit chat(QObject *parent = 0);
    int cht();
signals:
 
public slots:
    void chtShw();
};
 
#endif // CHAT_H
 Комментарий модератора 
Ставьте теги правильно.
Правила именования тем и оформления сообщений в разделе Qt



0



1068 / 650 / 229

Регистрация: 14.01.2016

Сообщений: 2,031

Записей в блоге: 9

09.04.2017, 20:06

2

Цитата
Сообщение от SkillKota
Посмотреть сообщение

chat.cpp:10: ошибка: C2039: Show: не является членом «chat»
main.cpp:15: ошибка: C3861: connect: идентификатор не найден

1) chat не может быть показан тк не является виджетом(QWidget).
2) Используйте QObject::connect



0



0 / 0 / 0

Регистрация: 23.11.2015

Сообщений: 13

12.04.2017, 08:37

 [ТС]

3

А как мне сделать так,что при нажатии кнопки открывалась другая форма,а первая закрывалась?



0



1068 / 650 / 229

Регистрация: 14.01.2016

Сообщений: 2,031

Записей в блоге: 9

12.04.2017, 11:04

4

SkillKota, Если нужно только это, то пускай первая форма генерирует сигнал открытия для другой, с bool значением. Затем можно данный сигнал подсоединить к слоту setVisible у другой формы. А затем скрыть первую форму.



0



SkillKota

0 / 0 / 0

Регистрация: 23.11.2015

Сообщений: 13

13.04.2017, 22:01

 [ТС]

5

Я уже пару дней бъюсь с сигналами и слотами.Вот,что я попытался сделать.
Правильно ли я делаю,что соединяю сигналы и слоты в main?
Я очень хочу понять ,как работать с сигналами.Пожалуйста помогите.
main.cpp

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "mainwindow.h"
#include<iostream>
#include <QApplication>
#include <QPushButton>
#include "chat.h"
//using namespace QObject;
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    chat cht;
    QPushButton enter;
    w.show();
    enter.show();
    QObject::connect(&enter,SIGNAL(clicked()),&cht,SLOT(chtShw()));
    QObject::connect(&w,SIGNAL(openChat()),&cht,stv());
    return a.exec();
}

mainwindow.cpp

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
void chtShw(){
   emit openChat();
}
void openChat(){
    MainWindow *mw=new MainWindow();
    mw.setVisible(false);
}

mainwindow.h

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
public slots:
    void chtShw();
 
signals:
    void openChat();
private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

chat.cpp

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
#include "chat.h"
#include "mainwindow.h"
chat::chat(QObject *parent) : QObject(parent)
{
 
}
 
void stv(){
    chat *ct=new chat();
    ct->setVisible(true);
}

chat.h

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef CHAT_H
#define CHAT_H
 
#include <QObject>
class chat : public QObject
{
    Q_OBJECT
public:
    explicit chat(QObject *parent = 0);
    int cht();
signals:
public slots:
    void stv();
};
#endif // CHAT_H



0



1068 / 650 / 229

Регистрация: 14.01.2016

Сообщений: 2,031

Записей в блоге: 9

14.04.2017, 11:08

6

Цитата
Сообщение от SkillKota
Посмотреть сообщение

MainWindow *mw=new MainWindow();

Объясните, что вы пытаетесь сделать этой строкой?



0



0 / 0 / 0

Регистрация: 23.11.2015

Сообщений: 13

15.04.2017, 23:38

 [ТС]

7

Пытаюсь сделать ссылку,чтобы обратиться к MainWindow



0



1068 / 650 / 229

Регистрация: 14.01.2016

Сообщений: 2,031

Записей в блоге: 9

18.04.2017, 10:00

8

Цитата
Сообщение от SkillKota
Посмотреть сообщение

Пытаюсь сделать ссылку,чтобы обратиться к MainWindow

MainWindow — это класс, а не объект, он не существует и к нему нельзя обратиться.
Изучите С++ на базовом уровне, прежде чем работать с Qt, иначе у вас будут большие проблемы даже с элементарными операциями.



0



0 / 0 / 0

Регистрация: 23.11.2015

Сообщений: 13

18.04.2017, 18:33

 [ТС]

9

Я знаю С++ на базовом уровне. Я не могу понять, как обратиться к форме.



0



1068 / 650 / 229

Регистрация: 14.01.2016

Сообщений: 2,031

Записей в блоге: 9

18.04.2017, 21:35

10

Цитата
Сообщение от SkillKota
Посмотреть сообщение

Я знаю С++ на базовом уровне. Я не могу понять, как обратиться к форме.

Если бы вы знали С++, вы бы понимали, какую чушь вы творите. Я же не просто так говорю.
Для того, чтобы обратиться к форме надо либо знать адрес формы, либо использовать сигнал-слотовое соединения для передачи сигналов в форму.



0



Update: Forum Guidelines & Code of Conduct

This topic has been deleted. Only users with topic management privileges can see it.

  • hi
    i’m new to qt. i have installed qt 5.5.1 for 32 bit windows 7 with microsoft visual studio 2012. I have cloned the source code of Qgroundcontrol through github desktop. when i try to build and compile the source code i am getting errrors as C2039 ‘isfinite’ is not a member of namespace ‘std’

  • Probably you did not activate C++11 standard.
    std::isfinite was invented in C++11, see http://en.cppreference.com/w/cpp/numeric/math/isfinite
    I’m not sure, but probably VS2012 C++ compiler does not support C++11.

У меня странная ошибка при попытке использовать ‘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.0VCINCLUDExutility(375) : error C2039: 'pointer' : is not a member of 'QJsonObject::iterator'
c:qtqt5.5.1msvc5.5msvc2013includeqtcoreqjsonobject.h(96) : see declaration of 'QJsonObject::iterator'
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(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.0VCINCLUDEalgorithm(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
]
..QJsonObjectIteratorIssuemain.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.0VCINCLUDExutility(375) : error C2146: syntax error : missing ';' before identifier 'pointer'
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(375) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(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.0VCINCLUDExutility(375) : see declaration of 'std::iterator_traits<_InIt>::pointer'
with
[
_InIt=QJsonObject::iterator
]
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExutility(375) : error C2868: 'std::iterator_traits<_InIt>::pointer' : illegal syntax for using-declaration; expected qualified-name
with
[
_InIt=QJsonObject::iterator
]

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

0

Решение

Другие решения

Других решений пока нет …

Windows Visual Studio 2010. Qt 4.7.1
При выполнении команд
qmake CONFIG-=debug_and_release CONFIG-=debug -recursive vacuum.pro
nmake
nmake install
Сборка не проходит. Выводит ошибки:
.optionsmanager.cpp(183) : error C2039: nativeLanguageName: не является членом «QLocale»
c:qt4.7.1includeqtcore../../src/corelib/tools/qlocale.h(110): см. объявление «QLocale»
.optionsmanager.cpp(184) : error C2039: nativeCountryName: не является членом «QLocale»
c:qt4.7.1includeqtcore../../src/corelib/tools/qlocale.h(110): см. объявление «QLocale»

Ошибка вот тут:

QString langName = locale.nativeLanguageName();

QString QLocale::nativeLanguageName() const
This function was introduced in Qt 4.8.

В инфе по сборке у Вас указано QT 4.5.2

Понравилась статья? Поделить с друзьями:

Не пропустите эти материалы по теме:

  • Яндекс еда ошибка привязки карты
  • C1b84 газон некст ошибка
  • C2013 mazda ошибка
  • C2011 ошибка мазда
  • C1b71 ошибка газон некст

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии