为什么我的 QQuick 应用程序在 Ubuntu 上崩溃?

为什么我的 QQuick 应用程序在 Ubuntu 上崩溃?

基本上我有(Game 类只是包装了 QGuiApplication):

int Game::run()
{
    QQuickView * mMainView = new QQuickView;
    mMainView->setResizeMode(QQuickView::SizeRootObjectToView);
    mMainView->setSource(QUrl("qrc:///main.qml"));

    mMainView->show();

    return mApp.exec();
}

主要的:

int main(int argc, char ** argv)
{
    Game game(argc, argv);
    return game.run();
}

还有 QML:

import QtQuick 2.2

Rectangle {
    width: 256
    height: 256
}

当我编译并运行时,它会像这样崩溃:

#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x00007ffff6858221 in QCoreApplication::arguments() () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#2  0x00007fffed9f9ad3 in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so
#3  0x00007fffed9f9fbd in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so
#4  0x00007fffeda06af2 in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so
#5  0x00007fffed9f9731 in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so
#6  0x00007ffff6fb4efe in QWindow::create() () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#7  0x00007ffff6fb57b0 in QWindow::setVisible(bool) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#8  0x000000000041f04c in Game::run (this=this@entry=0x7fffffffd9b0) at /home/xxxxxx/src/game.cpp:71
#9  0x000000000041e44a in main (argc=1, argv=0x7fffffffdc78) at /home/xxxxxx/main.cpp:11

什么鬼?我甚至无法运行最简单的 QQuick 应用程序。

答案1

问题在于,QGuiApplication的构造函数签名实际上是QGuiApplication(int & argc, char ** argv)

请注意参考&argc! :)

我已经通过值传递,因此当变量超出范围argc时应用程序就会崩溃。argc

相关内容