レンダリングとロジックの部分がC++であるのに対し、uiの部分がqml(メニューなど)で作成されるゲームを構築しようとしています。このために、QGLWidgetサブクラスを使用しています。ゲームはQmlで始まり(メイン関数でQDeclarativeContextを使用)、[NewGame]をクリックすると、QGLWidgetサブクラスが読み込まれます。このようなもの:
GameButton{
id:button2_1_1
x: 69
y: 101
width: 80
height: 80
onClicked:{ myObject.initialize(); myObject.show(); }
}
// myObject sets the context property to the object of my QGLWidget subclass
問題は、QGLWidgetをロードするときにQmlウィンドウを閉じる方法がわからないことです。私が行ったことと同様に、2つのウィンドウが同時に表示されます。
これがそのコードです。
//QtQuick1.0をインポートします//S605thEditionまたはMaemo5をターゲットにインポートしますQtQuick1.1をインポートします
Rectangle {
id:newGameMenu
width: 640
height: 360
signal button2Clicked();
onButton2Clicked: console.log("new game should start")
Image{
id:background
source:"menubackground.jpg"
anchors.fill:parent
Button2 {
id: button21
x: 70
y: 101
width: 42
height: 42
}
}
Button2{
id:button2_1_1
x: 69
y: 101
width: 44
height: 44
onClicked:{ myObject.abc(); myObject.show(); console.log("glwindow called"); }
}
}
main.cpp
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QDeclarativeView>
#include <QDeclarativeItem>
#ifndef GLWINDOW_H
#include "glwindow.h"
#endif
#include <QObject>
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QDeclarativeView view;
GLWindow w;
view.rootContext()->setContextProperty("myObject", &w);
view.setSource(QUrl::fromLocalFile(""));
view.show();
qDebug() << "into the qml";
return app->exec();
}