1
votes

I am trying to build a game in which the ui part is made in qml (menu etc) while the rendering and logic part is in C++. For this I'm using a QGLWidget subclass. The game starts with Qml (using a QDeclarativeContext in the main function) and on clicking 'NewGame', I am loading my QGLWidget subclass. Something like this:

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

The problem is that I can't figure out a way to close my Qml window when I load the QGLWidget. As with what I've done two windows are displayed simultaneously.

Here's the code for it.

// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5 import QtQuick 1.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();

}

4

4 Answers

1
votes

As with what I've done two windows are displayed simultaneously

I feels like you are showing two window, one QDeclarativeView and other QGLWidget. In that case, you should try to hide, your QDeclarativeView when you are showing QGLWidget,

1
votes
0
votes

Try setting .visible=false for the menu widget in onClicked.

0
votes

What about http://qt-project.org/forums/viewthread/15160/

Also I would use a QStackedWidget with 2 QWidgets: One would be QDeclarativeView that holds your QML and the other QGLWidget that holds your OpenGL; Moving between QML and OpenGL would mean calling QStackedWidget::setCurrent();