简体   繁体   English

使用clang的QT标头中的错误

[英]Errors in QT headers using clang

Questions: 问题:


My question is thus: How do I build my QT project without turning off warnings altogether (or having to sort through a million purposeless ones to find my own)? 因此,我的问题是:如何在不完全关闭警告的情况下构建我的QT项目(或者必须分类一百万个无目的的警告才能找到自己的警告)? Can I suppress warnings for just the QT headers? 我可以仅对QT标头抑制警告吗?

Details: 细节:


Issue 问题


A number of months ago, I started a QT project in QT-Creator. 几个月前,我在QT-Creator中启动了QT项目。 At the time I was using gcc 4.6. 当时我正在使用gcc 4.6。 After a bit other priorities asserted themselves and I found myself without time to work on the project until now. 经过一些其他优先事项的肯定,我发现自己直到现在都没有时间从事该项目。 In the interim I switched to using clang. 在此期间,我转而使用clang。 When I configured my QT project to use clang -- which project compiled without warnings in g++ -- it generated some 263 warnings all within the QT headers themselves. 当我将我的QT项目配置为使用clang时(该项目在g ++中编译时没有警告),它在QT标头本身内生成了263条警告。 Mostly sign-conversion and unreachable-code. 主要是符号转换和无法访问的代码。


Attempts 尝试次数


To try and get around this I added -isystem /path/to/QT/include/dir based on this entry in the Clang User Manual , but it did not seem to affect anything. 为了解决这个问题,我根据Clang用户手册中的此项添加了-isystem / path / to / QT / include / dir,但是它似乎没有任何影响。 Though I am not certain, I think it is because my code #include 's the QT headers by name, not by directory. 尽管我不确定,但我认为这是因为我的代码#include是按名称而不是按目录的QT标头。 While the solution to that might be to manually list every single QT header used (have not tried), it would mean I would have to update it every time I upgraded QT or used a new header. 解决方案可能是手动列出每个使用的QT标头(尚未尝试),但这意味着我每次升级QT或使用新标头时都必须对其进行更新。 Surely there is a better solution. 当然,有更好的解决方案。

As requested here is the actual compile command being executed: 根据要求,这里是实际执行的编译命令:

clang++ -c -pipe -Qunused-arguments -Weverything -cxx-isystem /path/to/qt/4.8.3/include/ -g -D_REENTRANT -DQT_NO_KEYWORDS -DQT_SHARED -I/path/to/qt/x86_64/4.8.3/mkspecs/unsupported/linux-clang -I. -I.moc -I.ui -I/path/to/qt/4.8.3/include/ -o .obj/main.o main.cpp

Specs 眼镜


I am using: 我在用:

  • Linux 3.2.0-40-generic #64-Ubuntu SMP x86_64 GNU/Linux Linux 3.2.0-40-通用#64-Ubuntu SMP x86_64 GNU / Linux
    • Though others on my team use Windows 虽然我团队中的其他人使用Windows
  • QT creator 2.6.2 QT创建者2.6.2
  • QT 4.8.3 QT 4.8.3
  • clang version 3.2 (trunk 165250) (llvm/trunk 165249) clang版本3.2(trunk 165250)(llvm / trunk 165249)
    • Target: x86_64-unknown-linux-gnu 目标:x86_64-unknown-linux-gnu

I will answer my own question because, as it turns out, it is a specific environmental quirk in this case. 我将回答我自己的问题,因为事实证明,在这种情况下,这是一个特定的环境怪癖。

I have two copies of the QT libraries on my dev machine, one system-wide and one project specific (included in the VCS). 我的开发机上有两个QT库副本,一个是系统范围的,另一个是特定项目的(包含在VCS中)。 The project libraries do not have qmake included, so I used my system qmake, which appended a different path than I was including in my -isystem specifications. 项目库中未包含qmake,因此我使用了系统qmake,该系统附加了与-isystem规范中不同的路径。 To solve this, I added 为了解决这个问题,我添加了

QMAKE_INCDIR_QT = 

to qmake.conf (in qt/mkspecs/unsupported/linux-clang/) 到qmake.conf(在qt / mkspecs / unsupported / linux-clang /中)

Since someone else on the project had fanangled qmake into using the project libraries everywhere else. 由于项目中的其他人使qmake陷入了在其他地方使用项目库的麻烦。

For those who stumble upon this question with a more general problem than the author. 对于那些偶然遇到这个问题的人,有一个比作者更普遍的问题。 Try inserting: 尝试插入:

LIBS_USED_FOR_QT = QtCore QtSql QtMultimediaWidgets QtSensors QtSvg QtXml QtPrintSupport QtWidgets QtQuick QtQml QtPositioning QtGui QtWebKitWidgets
for(somelib, $$list($$LIBS_USED_FOR_QT)) {
    QMAKE_CXXFLAGS += -isystem $$(QTDIR)/lib/$${somelib}.framework/Versions/5/Headers/
    QMAKE_CXXFLAGS += -isystem $$(QTDIR)/lib/$${somelib}.framework/Headers/
}

in your .pro file. 在您的.pro文件中。 Addtionally avoid includes like #include <QtCore/QtCore> writing #include <QtCore> instead 另外避免使用诸如#include <QtCore/QtCore>类的#include <QtCore/QtCore>编写#include <QtCore>

This tamed qt quite efficiently for me. 这对我来说非常有效地驯服了qt。

see also this source 另请参阅此来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM