i'm stuck with this for 2 days..
My code was building without any problems but since i made some changes that are not related with this (i think) it's not building anymore.
So i want to open a new window from a button clicked on a first window to open a second one and close the first one. I did as I saw in different tutorials. But the fact is that my firstWindow header doesn't recognize my secondWindow type and my error is :
C:\Users\johns\Documents\ESI\2Bac\2020-2021\dev4\pokerCafards\pokerCafards\guiApp\firstwindow.h:45: error: 'gameWindow' does not name a type; did you mean 'QMainWindow'?
In file included from gamewindow.h:6,
from gamewindow.cpp:1:
firstwindow.h:45:5: error: 'gameWindow' does not name a type; did you mean 'QMainWindow'?
gameWindow* gameWind;
^~~~~~~~~~
QMainWindow
As gameWindow is my secondWindow.
Here are my differents codes :
firstwindow.h
#ifndef FIRSTWINDOW_H
#define FIRSTWINDOW_H
#include "gamewindow.h"
#include <QMainWindow>
#include <QPushButton>
#include "player.h"
namespace Ui {
class firstWindow;
}
class firstWindow : public QMainWindow
{
Q_OBJECT
public:
explicit firstWindow(QWidget *parent = nullptr);
~firstWindow();
std::vector<metier::Player> getPlayers();
std::string getLineEditNameText();
std::string getLineEditAgeText();
void setPlayersText();
void updatePlayers(std::string name, std::string age);
private slots :
void on_buttonAdd_clicked();
void on_button_begin_clicked();
private:
std::vector<metier::Player> _players;
Ui::firstWindow *ui;
gameWindow* gameWind;
bool isNumber(const std::string& str);
};
#endif // FIRSTWINDOW_H
fisrtWindow.cpp
#include "firstwindow.h"
#include "ui_firstwindow.h"
#include <QDebug>
firstWindow::firstWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::firstWindow)
{
ui->setupUi(this);
connect(ui->button_add, SIGNAL(clicked()), this, SLOT(on_buttonAdd_clicked()));
}
firstWindow::~firstWindow()
{
delete ui;
}
std::vector<metier::Player> firstWindow::getPlayers() {
return _players;
}
bool firstWindow::isNumber(const std::string& str) {
for (char const &c : str) {
if (std::isdigit(c) == 0) return false;
}
return true;
}
std::string firstWindow::getLineEditNameText() {
return ui->lineEdit_nom->text().toStdString();
}
std::string firstWindow::getLineEditAgeText() {
return ui->lineEdit_age->text().toStdString();
}
void firstWindow::setPlayersText(){
ui->text_players->append(QString::fromStdString( getLineEditNameText() + " " + getLineEditAgeText() + "ans" + "\n"));
}
void firstWindow::on_buttonAdd_clicked() {
if(_players.size()==6) {
ui->label_avert_empty->setText("Vous etes déjà 6 joueurs.");
} else if(getLineEditAgeText().empty() || getLineEditNameText().empty() || !isNumber(getLineEditAgeText()) || (stoi(getLineEditAgeText())<8)) {
ui->label_avert_empty->setText("Vous devez remplir les 2 cases correctement.");
} else {
firstWindow::setPlayersText();
metier::Player player = metier::Player(getLineEditNameText(),(_players.size()+1), stoi(getLineEditAgeText())); //stoi() transforme string to int
_players.push_back(player);
ui->label_avert_empty->setText("Joueur ajouté, bienvenue " + ui->lineEdit_nom->text() + " !" +"\n");
ui->lineEdit_age->setText("");
ui->lineEdit_nom->setText("");
}
qDebug() << _players.size();
}
void firstWindow::on_button_begin_clicked() {
if(_players.size()<3) {
ui->label_avert_less3->setText("Il faut au moins 3 joueurs.");
} else {
gameWind = new gameWindow(_players);
gameWind->show();
close();
}
}
and my gameWindow.h (second window) :
#ifndef GAMEWINDOW_H
#define GAMEWINDOW_H
#include<QHBoxLayout>
#include <QDialog>
#include "firstwindow.h"
#include "game.h"
#include <QLayout>
namespace Ui {
class gameWindow;
}
class gameWindow : public QDialog
{
std::vector<metier::Player> _players;
Q_OBJECT
public:
explicit gameWindow(std::vector<metier::Player> players, QWidget *parent = nullptr);
explicit gameWindow(QWidget *parent = nullptr);
~gameWindow();
void setPlayerToPlay(int nbPlayer);
void setPlayerHand(int player);
// todo on an update Board
void setPlayersBoard();
void hideHand();
void showHand();
void showAnnouncedCard(metier::Card);
void showTrueCard();
void hideTrueCard();
void showAnswerQuestion();
void hideAnswerQuestion();
void hideQuestionCard();
void showQuestioncard();
void showAnsweringCard();
void hideAnsweringCard();
private:
Ui::gameWindow *ui;
QPushButton *button_Vrai;
QPushButton *button_False;
QPushButton *button_Rethrow;
};
#endif // GAMEWINDOW_H
If someone could help me that would be grateful. It's maybe just a small thing but i'm lost..
PS : I know my class names have to begin with an uppercase but i forgot :)