Прямо сейчас созданный QDialog не появляется. Есть ли способ помочь мне найти ошибку?Получение QDialog для отображения с функциями show или exec
Мой 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();
}
Диалог игрока: (один у меня возникают проблемы, чтобы получить показать)
#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();
}
если есть больше информации я могу предоставить, которые могли бы помочь процесс отладки, пожалуйста, дайте мне знать. Спасибо вам за помощь.
Я прочитал несколько других примеров, которые использовали show()
вместо exec()
. Есть ли разница? Прямо сейчас после ввода диалогового окна numberPlayers в диалоговом окне отображаются ни один из строк и combobox.
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() открыть диалоговое окно как не модальное и немедленно вернуться, exec() открыть диалоговое окно как модальное и дождаться возвращаемого значения вы пытались отобразить значение numberPlayers? qDebug() << numberPlayers; ценность хорошая? – Boo
Да, это хорошо, проблема заключается в том, что все виджеты, которые я создал для моего диалогового окна playerInfo, не отображаются – user3587954
Это по сути пустой диалог (пустое поле) – user3587954