Qt4:QMap导致“严格别名规则”编译错误

时间:2010-02-12 00:55:13

标签: c++ gcc qt4

我正在尝试在Qt 4.5中用C ++创建以下数据结构:

QMap<int, QMap<QString, QVector<QPointF> > > animation;

但是,在我的代码中包含此行会导致以下错误:

cc1plus: warnings being treated as errors
In file included from XXX/XXX/XXX/MainWindow.qt.C.tmp.C:113:
/usr/lib/qt4/include/QtCore/qmap.h: In member function ‘void MainWindow::exportAnn()’:
/usr/lib/qt4/include/QtCore/qmap.h:588: error: dereferencing pointer ‘y’ does break strict-aliasing rules
/usr/lib/qt4/include/QtCore/qmap.h:586: note: initialized from here
Command exited with non-zero status 1

我的组织要求我将所有警告视为错误,因此我不能简单地忽略这一点。这是Qt中的一个错误,还是我做错了什么?

1 个答案:

答案 0 :(得分:0)

您提到的代码适用于Intel / Mac OS X上的Qt 4.6.1和GCC 4.4.1。

$ cat a.cpp #include <QtCore>
void foo (QMap<int, QMap<QString, QVector<QPointF> > > &map)
  { map.clear(); }
$ g++-4.4-fsf -c -DQT_CORE_LIB -DQT_SHARED -I/Library/Frameworks/QtCore.framework/Versions/4/Headers a.cpp -W -Wall -Werror -g -O3 -fPIC
$

所以你的问题可能是通过升级到Qt 4.6.1来解决的。 (除非它是一个特定于编译器目标的bug,这似乎不太可能;另外,你还没有告诉我们你正在编译什么平台。)

相关问题