Qt5:错误:'WA_LockPortraitOrientation'不是'Qt'的成员



我正在尝试将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'

是的,正如您自己指出的那样,这些在Qt 5中删除了。

原因是这些是Symbian独有的功能,如果他们只在某个平台上工作,特别是如果Qt 5本身不支持该平台,那么这些事情只会让Qt用户感到困惑。

相应的 gerrit 更改可以在此处找到:

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

它比硬编码十六进制值更干净、更好。这也是现有Qt模块遵循的推荐方式,如QtSerialPort。

我通过更改以下行来修复它:

#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.

最新更新