首页 > 解决方案 > qlist.h(466):错误 C2061:语法错误:标识符“n”

问题描述

我在我的一个项目中包含 Qt 库时遇到问题。包括:

#include <QtCore/QString>
#include <QtXml/QDomDocument>
#include <iostream>

#pragma push_macro("realloc")
#undef realloc
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#pragma pop_macro("realloc")

包括 QFile QFileInfo QDir 导致此错误:

C:\qt\5.15.0\msvc2019_64\include\QtCore\qlist.h(466): error C2061: syntax error: identifier 'n'
C:\qt\5.15.0\msvc2019_64\include\QtCore\qlist.h(464): note: while compiling class template member function 'void QList<QString>::node_construct(QList<QString>::Node *,const T &)'
      with
      [
          T=QString
      ]
C:\qt\5.15.0\msvc2019_64\include\QtCore\qlist.h(625): note: see reference to function template instantiation 'void QList<QString>::node_construct(QList<QString>::Node *,const T &)' being compiled
      with
      [
          T=QString
      ]
C:\qt\5.15.0\msvc2019_64\include\QtCore\qlist.h(854): note: while compiling class template member function 'QList<QString>::QList(const QList<QString> &)'
C:\qt\5.15.0\msvc2019_64\include\QtCore\qstringlist.h(117): note: see reference to function template instantiation 'QList<QString>::QList(const QList<QString> &)' being compiled
C:\qt\5.15.0\msvc2019_64\include\QtCore\qstringlist.h(112): note: see reference to class template instantiation 'QList<QString>' being compiled
C:\qt\5.15.0\msvc2019_64\include\QtCore\qlist.h(505): error C2061: syntax error: identifier 'current'
C:\qt\5.15.0\msvc2019_64\include\QtCore\qlist.h(487): note: while compiling class template member function 'void QList<QString>::node_copy(QList<QString>::Node *,QList<QString>::Node *,QList<QString>::Node *)'
C:\qt\5.15.0\msvc2019_64\include\QtCore\qlist.h(860): note: see reference to function template instantiation 'void QList<QString>::node_copy(QList<QString>::Node *,QList<QString>::Node *,QList<QString>::Node *)' being compiled

使用 push/pop 宏是因为与 realloc 模板类似的错误,此处已解决:Qt: not enough arguments for function-like macro invocation 'realloc', qvector.h

标签: c++qtinclude

解决方案


推荐阅读