Splatify
7th February 2011, 06:37
Ok this is the (relevant) code i have:
quiz.cpp
void Quiz::on_NextButton_clicked()
{
QuizDialog question;
question.myfile.open("C:\\questions.txt");
if(question.myfile.is_open()){
question.next_question();
}
void Quiz::next_question(){
while(!(line=="<EOQ>")){
getline(myfile, line);
if(line == "<QUESTION_TEXT>"){
getline(myfile, line);
ui->QuestionLabel->setText(line.c_str());
qDebug() << "Question: " << line.c_str();
}
}
quiz.h
#ifndef QUIZ
#define QUIZ
#include <iostream>
#include <fstream>
#include <string>
#include <QDialog>
using namespace std;
namespace Ui {
class Quiz;
}
class Quiz : public QDialog
{
Q_OBJECT
public:
explicit Quiz(QWidget *parent = 0);
~Quiz();
ifstream myfile;
string line;
void next_question();
private:
Ui::Quiz *ui;
private slots:
void on_NextButton_clicked();
};
Ok so here's the problem. The file is opening fine. The function 'next_question();' then runs and "qDebug() << "Question: " << line.c_str();" does output the relevant information to the debugger.
However in the line above this, 'ui->QuestionLabel->setText(line.c_str());' i have asked for the caption on my form to be set to whatever the current value of line is. For some reason this does not seem to work. I know that the file is being access and I know that the correct line is being found. However I cannot output this information to the form. :( Could someone please explain what's up??
Thanks for your time and trouble. :)
quiz.cpp
void Quiz::on_NextButton_clicked()
{
QuizDialog question;
question.myfile.open("C:\\questions.txt");
if(question.myfile.is_open()){
question.next_question();
}
void Quiz::next_question(){
while(!(line=="<EOQ>")){
getline(myfile, line);
if(line == "<QUESTION_TEXT>"){
getline(myfile, line);
ui->QuestionLabel->setText(line.c_str());
qDebug() << "Question: " << line.c_str();
}
}
quiz.h
#ifndef QUIZ
#define QUIZ
#include <iostream>
#include <fstream>
#include <string>
#include <QDialog>
using namespace std;
namespace Ui {
class Quiz;
}
class Quiz : public QDialog
{
Q_OBJECT
public:
explicit Quiz(QWidget *parent = 0);
~Quiz();
ifstream myfile;
string line;
void next_question();
private:
Ui::Quiz *ui;
private slots:
void on_NextButton_clicked();
};
Ok so here's the problem. The file is opening fine. The function 'next_question();' then runs and "qDebug() << "Question: " << line.c_str();" does output the relevant information to the debugger.
However in the line above this, 'ui->QuestionLabel->setText(line.c_str());' i have asked for the caption on my form to be set to whatever the current value of line is. For some reason this does not seem to work. I know that the file is being access and I know that the correct line is being found. However I cannot output this information to the form. :( Could someone please explain what's up??
Thanks for your time and trouble. :)