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