且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

QT5迁移和提升:if.hpp:宏参数不匹配错误

更新时间:2023-10-23 10:03:28

下面是我已经能够淘净了几个小时后,找到***的解决方法。这基本上是其他人一直在说,但有一些澄清。


  • 的问题与moc.exe做不正确处理升压宏。

  • 在为了解决这个问题,我们通过定义包括对moc.exe过程中后卫,但不是经常源代码编译禁止包含升压头。

  • 这可以通过添加以下code到项目文件(例如myproject.pro)最容易实现的

     #确保QMAKE_MOC包含商务部可执行文件路径
    负载(MOC)#每个Boost头文件包括你...
    QMAKE_MOC + = -DBOOST_INCLUDE_GUARD_GOES_HERE


例如,如果我想使用的日志库,我有:

 的#include<升压/日志/ trivial.hpp>

如果我打开了头文件,我可以在上面看到,包括后卫被命名为 BOOST_LOG_TRIVIAL_HPP_INCLUDED _ 。因此,在.pro文件中相应的行内容如下:

  QMAKE_MOC + = -DBOOST_LOG_TRIVIAL_HPP_INCLUDED_

如果一对夫妇的更多音符他们相关的人:


  • 如果你觉得这不工作,确保运行的qmake和重建项目,只要你添加一个新行到您的项目文件。

  • 我使用的Windows 7 32位使用Qt 5.0.1升压1.53和建设中QtCreator MSVC2010。

In qt 4.8 I used boost (1.52) It all was ok... Now I try to move to QT5 and get if.hpp: Macro argument mismatch error on line 131 BOOST_MPL_AUX_NA_SPEC(3, if_). In some QT forums there is presented a solution like this:

#ifndef Q_MOC_RUN
// All boost includes
#endif // Q_MOC_RUN

in each my file that uses boost... So question here is - how to tell to boost that QT is not ready for BOOST_MPL_AUX_NA_SPEC and that boost shall use some more primitive preprocessor syntax one that would be QT5 compatible?


Update: found this solution yet it seems not to bring any effect at all in Qt5=(

Here is the best workaround I've been able to find after scouring the net for a few hours. It is basically what other folks have been saying, but with a few clarifications.

  • The problem has to do with moc.exe not correctly handling Boost macros.
  • In order to get around this, we disable inclusion of Boost headers by defining their include guards for the moc.exe process, but not for regular source compilation.
  • This can be accomplished most easily by adding the following code to your project file (e.g. myproject.pro):

    # ensure QMAKE_MOC contains the moc executable path
    load(moc) 
    
    # for each Boost header you include...
    QMAKE_MOC += -DBOOST_INCLUDE_GUARD_GOES_HERE 
    

For example, if I want to use the logging library, I'd have:

#include <boost/log/trivial.hpp>

If I open up the header file, I can see at the top that the include guard is named BOOST_LOG_TRIVIAL_HPP_INCLUDED_. Therefore, the corresponding line in the .pro file would read:

QMAKE_MOC += -DBOOST_LOG_TRIVIAL_HPP_INCLUDED_

A couple of more notes in case they are relevant for anyone:

  • If you find this not working, make sure to run qmake and rebuild your project whenever you add a new line to your project file.
  • I'm using Boost 1.53 with Qt 5.0.1 and building for MSVC2010 within QtCreator on Windows 7 32-bit.