0

Right now the QDialog I created is not showing up. Is there any way you can help me find the error?

My main.cpp

#include <QApplication>
#include "numplayers.h"
#include "playerinfo.h"
#include "mainwindow.h"

int main( int argv, char* argc[] ) {
    int numberPlayers;
  QApplication app( argv, argc );
  MainWindow mw;
  numPlayers pPlayers;
   playerInfo pInfo;
  if (pPlayers.exec())
  {
    numberPlayers = pPlayers.returnInput();
  }

  for (int i = 0; i < numberPlayers; i++)
  {
    if(pInfo.exec())
    {
      int index = pInfo.getIndex();
      QString name = pInfo.getName();
          // do something with these..
      mw.setPlayerData(index, name, i);
    }
  }
  mw.setGUIWidgets(numberPlayers);
  mw.createCentralWidget();
  mw.show();

  return app.exec();
}

playerInfo Dialog: (the one I am having trouble to get show up)

#include "playerinfo.h"
#include <QDialogButtonBox>
#include <QLayout>
#include <QComboBox>
#include <QLineEdit>


playerInfo::playerInfo(QWidget *parent) :
    QDialog(parent)
{
    QVBoxLayout *layout = new QVBoxLayout;
    this->setLayout(layout);

    lineEdit = new QLineEdit; // create line edit
    layout->addWidget(lineEdit);

    comboBox = new QComboBox; // create combo box and add items to it
    QStringList items = QStringList() << "Hat" << "Car" << "Shoe" << "SpaceShip" << "Basketball" << "Ring";
    comboBox->addItems(items);
    layout->addWidget(comboBox);



    // create button box
    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    layout->addWidget(buttonBox);
}

QString playerInfo::getName() const
{
    return lineEdit->text();
}

int playerInfo::getIndex() const
{
    return comboBox->currentIndex();
}

if there is any more information I can provide that could help with the debugging process please let me know. Thank you for all the help.

I read some other examples that used show() instead of exec(). Is there a difference? Right now after the numberPlayers dialog is entered none of the lineedits and comboboxes show up in the dialog.

Edit:

playerInfo.h

#ifndef PLAYERINFO_H
#define PLAYERINFO_H
#include <QDialogButtonBox>
#include <QLayout>
#include <QComboBox>
#include <QLineEdit>
#include <QDialog>
#include <QWidget>

class QLineEdit;
class QComboBox;

class playerInfo : public QDialog
{
    Q_OBJECT
public:
    explicit playerInfo(QWidget *parent = 0);
    QString getName() const;
    int getIndex() const;

private:
    int max_players;
    QVBoxLayout *layout ;
    QDialogButtonBox *buttonBox;
    QComboBox *comboBox;
    QLineEdit *lineEdit;
};

#endif // MYDIALOG_H
  • hi, show() open the dialog as non modal and return immediatly, exec() open the dialog as modal and wait for the returned value have you tried to display the value of numberPlayers ? qDebug() << numberPlayers; the value is good ? – Boo Apr 30 '14 at 22:27
  • yes the value is good, the issue i am having is that all the widgets I created for my playerInfo dialog are not showing up – user3587954 Apr 30 '14 at 22:31
  • it is essentially a blank dialog (blank box) – user3587954 Apr 30 '14 at 22:32
  • con you post your playerInfo.h please, i'm not reproduicing your issue – Boo Apr 30 '14 at 22:51
  • really I don't see error, are you sure the window you see is not your mainwindow ? you should try pInfo.exec() right after declaring it to test – Boo Apr 30 '14 at 23:07

1 Answers1

0

It worked OK for me. As you haven't posted the code of numPlayers class, I initialised int numberPlayers = 3;. playerInfo dialogue was shown thrice and then main window appeared. It looks like the window you are seeing is the main window. May be numberPlayers = pPlayers.returnInput(); returning 0. Add qDebug() << numberPlayers; to see if you are getting a positive value.

ramtheconqueror
  • 1,907
  • 1
  • 22
  • 35
  • yes the numberPlayers value I receive is a number that correlates with the users selection from the input dialog 2 - 4 people – user3587954 May 01 '14 at 18:12
  • the numPlayers class is just a dialog that contains a QInputDialog prompting for a user to enter a number between 2 - 4 – user3587954 May 01 '14 at 18:12