2

I have a problem including Qt libraries to one of my projects. The includes are:

#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")

Includes QFile , QFileInfo and QDir cause this error:

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

The push/pop macro is used because of similar error with realloc template, which was resolved here: Qt: not enough arguments for function-like macro invocation 'realloc', qvector.h.

nocturne
  • 627
  • 3
  • 12
  • 39
  • 1
    This is very strange. I just added those #includes to one of my .cpp files and it doesn't complain about anything (I removed the realloc stuff). What version of Qt do you have installed? – Joseph Larson Mar 29 '21 at 19:03
  • I have Qt 5.15.0. I think they fixed something like this in Qt 6.0.0 (https://bugreports.qt.io/browse/QTBUG-86395). But there has to be some other problem since in my other project it is working fine. – nocturne Mar 30 '21 at 06:39
  • 1
    I'm also on 5.15.x – Joseph Larson Mar 30 '21 at 13:40
  • The reason this happened was, redefinition of new keyword. I had to do push/pop macro for new keyword as well. But thanks. – nocturne Mar 31 '21 at 11:17
  • 1
    The order of your includes might clean this up, depending on where that keyword is. Is it your code that redefines realloc? That seems particularly scary. – Joseph Larson Mar 31 '21 at 19:13
  • 1
    Only realloc uses the redefined new? Pushing realloc alone will not solve your problem. Most likely the redefinition of new is incomplete. Provide a complete redefinition of new. – Laszlo Apr 06 '21 at 05:47
  • 2
    Problem is that "placement new" is not compatible with re#define-d new. See https://stackoverflow.com/questions/4990880/replacing-new-with-macro-conflicts-with-placement-new Both problematic lines in qlist.h contain new with placement pointer: `new (n) T(t); // qlist.h 466` and somewhere you may find a macro like this: `#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)` `#define new DEBUG_NEW` – Pavel Peřina Sep 28 '21 at 09:38
  • I already resolved it by rearanging the positions of the includes, but Thanks Pavel. – nocturne Sep 29 '21 at 10:49

0 Answers0