基本上我有(游戏类只是包装 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 应用程序..
问题在于
QGuiApplication
构造函数的签名实际上是QGuiApplication(int & argc, char ** argv)
.请注意参考
&
!argc
:)我已经
argc
按值传递,所以当argc
变量超出范围时应用程序崩溃了。