als Anfänger in C++ & QT hoffe ich bei Euch eine Antwort auf ein mittlerweile mich nervendes Problem zu bekommen.
Folgender Situation:
Ich habe ein MainWindow und mittels einem Button wird ein QDialog aufgerufen. Im QDialog habe ich noch 2 Eingabefelder definiert, deren Werte dann
an das MainWindow übergeben wird. Die Eingabefelder heissen: w_goal & w_assist, den Dialog hab ich mittels Creator erstellt.
Nur das klappt nicht ganz so. Ich bekomme die Fehlermeldung: "expect primary-expression before "." token, bei Abfrage der Werte aus dem Dialog.
Fehlerstelle: void newGame::slotScoreResult() in newGames.cpp
Die Methode sollte mittels "return" den Wert des QLineEdit-Feldes w_goal & w_assist an das MainWindow übergeben.
Bei meinen Recherechen im iNet habe ich leider keinen erfolgreichen Hinweis gefunden, wie gesagt ich bin Neuling. Hoffentlich erfahre ich hier Hilfe.
Meine Codes
newGames.cpp:
Code: Alles auswählen
//#include <QApplication>
#include <QKeyEvent>
#include <QPushButton>
#include <QMessageBox>
#include <QMapIterator>
#include <math.h>
#include "config.h"
#include "defines.h"
#include "newgame.h"
#include "ui_newgame.h"
#include "score.h"
#define seperator ","
newGame::newGame(QWidget *parent) :
QStackedWidget(parent),
ui(new Ui::newGame)
{...
ui->setupUi(this);
void newGame::slotGoal()
{
score_Widget = new Score(this);
home_away ? score_Widget->setWindowTitle("GOAL!!! - " + ui->Home_Team->text()):score_Widget->setWindowTitle("GOAL - " + ui->Away_Team->text());
connect(Score::buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),this,SLOT(slotScoreResult())); //HIER HAB ICH AUCH NOCH EINEN FEHLER: nicht zugeordnet
connect(Score::buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(slotScoreAbbrechen())); //HIER HAB ICH AUCH NOCH EINEN FEHLER: nicht zugeordnet
score_Widget->show();
}
void newGame::slotScoreResult()
{
[b]goal = Score.getGoal_Assist("goal"); //HIER KOMMT DIE FEHLERMELDUNG expect primary-expression before "." token
assist = Score.getGoal_Assist("assist"); //HIER KOMMT DIE FEHLERMELDUNG expect primary-expression before "." token[/b]
if(!goal.isEmpty())
{
gameTimeString(min_played_time, sec_played_time);
QString team = home_away ? "0" : "1";
QMap<QString, int>::iterator i;
for (i=game->begin();i!=game->end();i++)
{
if (i.key()== ui->Home_Team->text() && home_away==1) i.value()++;
if (i.key()== ui->Away_Team->text() && home_away==0) i.value()++;
}
ui->Home_Score->display(game->value(ui->Home_Team->text()));
ui->Away_Score->display(game->value(ui->Away_Team->text()));
setFocus();
// checkMap();
delete score_Widget;
}
}
......
Code: Alles auswählen
#ifndef NEWGAME_H
#define NEWGAME_H
#include <QStackedWidget>
#include <QPushButton>
#include <QPalette>
#include <QTimer>
#include <QDialog>
#include <QLineEdit>
#include <QMap>
#include <QComboBox>
#include <QList>
namespace Ui {
class newGame;
}
class newGame : public QStackedWidget
{
Q_OBJECT
public:
newGame(QWidget *parent = 0);
~newGame();
QTimer *game_Timer;
QDialog *score_Widget;
int new_game, game_Timer_stop;
// Timer Variablen definieren
double game_time, min_game_time, sec_game_time, ges_game_time;
double played_time, min_played_time, sec_played_time, ges_played_time;
// Spielstand definieren
int score_away, score_home;
// Variable für Tore & Strafen definieren - 1=home, 0=away
int home_away;
//Tabelle für Team & Score
QMap <QString, int> *game;
//Penalties
QList <QString> *home_penalty;
QList <QString> *away_penalty;
QString goal, assist;
/* // Array für den Zusammenhang TEAM & SCORE definieren
QString team[2];
double score[2];
*/
// Strings für die Anzeige & Logging definieren
QString TimeString;
QString gameTimeString(double min, double sec);
//QString assist, goal;
// QComboBox *combobox_homeTeam;
// QComboBox *combobox_awayTeam;
void resetPIM();
private:
Ui::newGame *ui;
public slots:
void slotLive();
void slotSimulation();
void slotCorrection();
void slotUpdateTimeDigits();
void slotGameTimer_update();
void slotTimerRecalc();
void slotF12();
void slotF1();
void slotHomeGoal();
void slotAwayGoal();
void slotGoal();
void slotScoreResult();
void checkMap();
private slots:
void keyPressEvent(QKeyEvent *event);
protected slots:
void slotScoreOK();
void slotScoreAbbrechen();
};
#endif // NEWGAME_H
Score.h
Code: Alles auswählen
#ifndef _SCORE_H_
#define _SCORE_H_
#include <QDialog>
#include <QWidget>
#include <QDialogButtonBox>
#include <QString>
#include <QLineEdit>
namespace Ui {
class Score;
}
class Score : public QDialog
{
Q_OBJECT
public:
Score(QWidget *parent = 0);
~Score();
QLineEdit *w_goal, *w_assist;
QDialogButtonBox *buttonBox;
QString getGoal_Assist(const QString& element);
private:
Ui::Score *ui;
};
#endif // SCORE_H
Code: Alles auswählen
#include "score.h"
#include "ui_score.h"
Score::Score(QWidget *parent) :
QDialog(parent),
ui(new Ui::Score)
{
ui->setupUi(this);
ui->goal->setText("0");
ui->assist->setText("0");
}
Score::~Score()
{
delete ui;
}
QString Score::getGoal_Assist(const QString &element)
{
if(element=="goal") return ui->w_goal->text();
if(element=="assist") return ui->w_assist->text();
}