Is the player_menu object being deleted or just hidden? This example I think captures your structure, and it works:
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
};
{
Q_OBJECT
PlayerMenu *player_menu; //the menu for the player
public:
player_menu = new PlayerMenu(parent);
player_menu->show();
}
~GameLogic() {
delete player_menu;
}
};
Q_OBJECT
public:
setCentralWidget
(new QLabel("Main Window",
this));
gl = new GameLogic("dummy", 1, this);
}
~StartMenu() {
delete gl;
}
public slots:
private:
GameLogic *gl;
};
int main(int argc, char *argv[])
{
StartMenu m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class PlayerMenu: public QDialog {
Q_OBJECT
public:
PlayerMenu(QWidget *p = 0): QDialog(p) { }
};
class GameLogic : public QObject
{
Q_OBJECT
PlayerMenu *player_menu; //the menu for the player
public:
GameLogic(QString player_name, int num_of_AI, QWidget *parent = 0) {
player_menu = new PlayerMenu(parent);
player_menu->show();
}
~GameLogic() {
delete player_menu;
}
};
class StartMenu: public QMainWindow {
Q_OBJECT
public:
StartMenu(QWidget *p = 0): QMainWindow(p), gl(0) {
setCentralWidget(new QLabel("Main Window", this));
gl = new GameLogic("dummy", 1, this);
}
~StartMenu() {
delete gl;
}
public slots:
private:
GameLogic *gl;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
StartMenu m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
The reason I asked about your QPointer is that I think you wanted a QScopedPointer in order that it do the memory deallocation during destruction.
Bookmarks