我正在尝试将Qt4 / Symbian项目编译为Qt5,同时保留对Qt4 / Symbian的支持。
目前MainWindow::setOrientation
自动生成的样板功能给我带来了麻烦。
它给了我这些编译错误:
error: 'WA_LockPortraitOrientation' is not a member of 'Qt'
error: 'WA_LockLandscapeOrientation' is not a member of 'Qt'
error: 'WA_AutoOrientation' is not a member of 'Qt'
答案 0 :(得分:5)
是的,正如你自己记下的那样,那些在Qt 5中删除了。
原因是这些仅仅是Symbian的功能,如果Qt用户只在特定平台上工作,这些事情就会让他们感到困惑,特别是如果Qt 5甚至不支持该平台,那么这就是它。
相应的细菌变化可以在这里找到:
https://codereview.qt-project.org/#change,11280
您需要更改这些行
#if QT_VERSION < 0x040702
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
到这些:
#if (QT_VERSION < QT_VERSION_CHECK(4, 7, 2)) || (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
// Qt 5 has removed them.
有条件地允许基于Qt版本的某些功能的好方法是:
#if (QT_VERSION < QT_VERSION_CHECK(4, 7, 2)) || (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
...
#endif
它比硬编码十六进制值更清晰,更好。它也是existing Qt modules follow的推荐方式,如QtSerialPort。
答案 1 :(得分:2)
我通过更改这些行来修复它:
#if QT_VERSION < 0x040702
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
到这些:
#if (QT_VERSION < QT_VERSION_CHECK(4, 7, 2)) || (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
// Qt 5 has removed them.