Results 1 to 6 of 6

Thread: Dialog Class inheriting QDialog Disappears Quickly After Loading.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Location
    Utah
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Dialog Class inheriting QDialog Disappears Quickly After Loading.

    Hi Guys,

    So this problem has stumped me for a while. I have a class that inherits QDialog. When I call it from my class that inherits QObject, it disappears quickly after loading.

    I have read many posts about making sure you create the dialog on the heap rather than the stack. I am following this advice but am still having troubles.

    I have included my relevant code as well as a diagram showing the hierarchy of our program.



    Qt Code:
    1. //GameLogic.h
    2.  
    3. #include <vector>
    4. #include <string>
    5. #include <iostream>
    6. #include <ctime>
    7. #include <QObject>
    8. #include "PlayerMenu.h"
    9. #include "AI.h"
    10. #include "GameBoard.h"
    11. #include <QtGui/QApplication>
    12. #include <qpointer.h>
    13. using namespace std;
    14.  
    15. class GameLogic : public QObject
    16. {
    17. Q_OBJECT
    18. QPointer<PlayerMenu> player_menu; //the menu for the player
    19. Player* human_player;
    20.  
    21. public:
    22. //constructor
    23. GameLogic(string player_name, int num_of_AI, QWidget *parent = 0);
    24.  
    25. //destructor
    26. ~GameLogic();
    27. };//end of Class
    28. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // GameLogic.cpp : Liars Dice
    2. #include "GameLogic.h"
    3. #include "time.h"
    4. #include <iostream>
    5.  
    6. //Constructor with user defined number of AI players 1-4
    7. GameLogic::GameLogic (string player_name, int num_of_ai, QWidget *parent)
    8. {
    9. player_menu = new PlayerMenu(parent);
    10.  
    11. //set up the rest of the connectors
    12. connect(player_menu, SIGNAL(sig_makeBet(int, int)), this, SLOT(bet(int, int)));
    13. connect(player_menu, SIGNAL(sig_startRound()), this, SLOT(slot_startRound()));
    14. connect(player_menu, SIGNAL(sig_moveMade()),this, SLOT(moveMade()));
    15.  
    16. player_menu->show();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef PLAYERMENU_H
    2. #define PLAYERMENU_H
    3.  
    4. #include <iostream>
    5. #include <stdio.h>
    6. #include <stdlib.h>
    7. #include <time.h>
    8. #include <string>
    9. #include "ui_PlayerMenu.h"
    10. #include <qdialog.h>
    11. #include "GameBoard.h"
    12.  
    13. //class GameLogic;
    14.  
    15. using namespace std;
    16. class PlayerMenu : public QDialog
    17. {
    18. Q_OBJECT
    19. public:
    20. PlayerMenu(QWidget *parent=0);
    21. ~PlayerMenu();
    22. ...
    23. ....
    24. }#endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //PlayerMenu.cpp : Liar's Dice
    2. #include "PauseMenu.h"
    3. #include <qpushbutton.h>
    4. #include <qmessagebox.h>
    5. #include <iostream>
    6. #include <sstream>
    7.  
    8. //Default constructor
    9. PlayerMenu::PlayerMenu(QWidget *parent)
    10. : QDialog(parent)
    11. {
    12. //set board
    13. ui.setupUi(this);//playermenu
    14.  
    15. //initialize variable
    16. move_not_made = true;
    17. player_move = 0;
    18. sec = 0;
    19.  
    20. //set these values to prevent players from
    21. //making illegal moves.
    22. minDie = 0;
    23. minVal = 0;
    24. ui.sb_diceCount->setMinimum(minDie);
    25. ui.tb_newsFeed->setPlainText("");
    26.  
    27. //set listenens for buttons
    28. connect(ui.btn_Bet, SIGNAL(clicked()), this, SLOT(Bet()));
    29. connect(ui.btn_callBluff, SIGNAL(clicked()), this, SLOT(callBluff()));connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(pushedOne()));
    30. connect(ui.btn_callSpotOn, SIGNAL(clicked()), this, SLOT(callSpotOn()));connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(pushedTwo()));
    31. connect(ui.pushButton_3, SIGNAL(clicked()), this, SLOT(pushedThree()));
    32. connect(ui.pushButton_4, SIGNAL(clicked()), this, SLOT(pushedFour()));
    33. connect(ui.pushButton_5, SIGNAL(clicked()), this, SLOT(pushedFive()));
    34. connect(ui.pushButton_6, SIGNAL(clicked()), this, SLOT(pushedSix()));
    35. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help!

    Edit:
    I forgot to also include that I want the PlayerMenu (QDialog) to be modeless. I have the PlayerMenu interacting with the GameLogic through signals.

    The main problem I have is that I want the game to start when I load the dialog.

    However if I put a signal in the constructor of PlayerMenu to start the game, then the game starts before the dialog is loaded.

    If I use exec() It blocks the game logic until the dialog is closed which defeats the purpose.
    Last edited by shandib1823; 12th May 2011 at 00:48. Reason: updated contents

Similar Threads

  1. Replies: 1
    Last Post: 7th March 2011, 14:02
  2. my window disappears quickly
    By Abeer in forum Newbie
    Replies: 2
    Last Post: 30th May 2010, 01:04
  3. Stop QDialog from inheriting parent's palette.
    By Avrohom in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2009, 04:59
  4. QListWidget inheriting custom class
    By phannent in forum Qt Tools
    Replies: 1
    Last Post: 4th August 2008, 14:39
  5. QDialog::exec() cereates no modal dialog
    By sboesch in forum Qt Programming
    Replies: 8
    Last Post: 27th March 2006, 17:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.