当应用程序启动时,Qt for iOSlocking正面。 (qiosscreen.mm断言)
我将Qt for iOS项目迁移到Qt 5.5。 至less在iOS 5.1.1中,如果您在设备面朝上启动应用程序,则应用程序无法启动。 一个断言在第344行的qiosscreen.mm中显示错误。下面是Qt源代码失败的函数:
Qt::ScreenOrientation QIOSScreen::orientation() const { // Auxiliary screens are always the same orientation as their primary orientation if (m_uiScreen != [UIScreen mainScreen]) return Qt::PrimaryOrientation; UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; // At startup, iOS will report an unknown orientation for the device, even // if we've asked it to begin generating device orientation notifications. // In this case we fall back to the status bar orientation, which reflects // the orientation the application was started up in (which may not match // the physical orientation of the device, but typically does unless the // application has been locked to a subset of the available orientations). if (deviceOrientation == UIDeviceOrientationUnknown) deviceOrientation = UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation); // If the device reports face up or face down orientations, we can't map // them to Qt orientations, so we pretend we're in the same orientation // as before. if (deviceOrientation == UIDeviceOrientationFaceUp || deviceOrientation == UIDeviceOrientationFaceDown) { Q_ASSERT(screen()); return screen()->orientation(); } return toQtScreenOrientation(deviceOrientation); }
它显示了一个断言
Q_ASSERT(screen());
screen()必须返回0,所以screen() – > orientation()正试图推断一个空指针。 那个screen()函数是在父类QPlatformScreen中定义的:
QScreen *QPlatformScreen::screen() const { Q_D(const QPlatformScreen); return d->screen; }
该类的构造函数将d-> screen初始化为0:
QPlatformScreen::QPlatformScreen() : d_ptr(new QPlatformScreenPrivate) { Q_D(QPlatformScreen); d->screen = 0; }
从评论中,我推断d->屏幕设置在方向为纵向或横向时的某个点,然后当面朝上/朝下时,它会回落到那个位置。 由于它是从正面开始的,所以没有先有的价值可以退缩。
有没有其他人遇到过这个问题,还是有解决办法? 顺便说一句,我不是从Qt源build设,不想,所以如果我可以避免这种情况,改变他们的代码是不是我的解决scheme。
我发现,这似乎只是从XCode或QtCreator启动应用程序时发生。 如果我按照正常运行的方式在设备上启动应用程序,这个错误似乎已经被避免了。