Ok this is the (relevant) code i have:

quiz.cpp
Qt Code:
  1. void Quiz::on_NextButton_clicked()
  2. {
  3. QuizDialog question;
  4. question.myfile.open("C:\\questions.txt");
  5. if(question.myfile.is_open()){
  6. question.next_question();
  7. }
  8.  
  9. void Quiz::next_question(){
  10. while(!(line=="<EOQ>")){
  11. getline(myfile, line);
  12. if(line == "<QUESTION_TEXT>"){
  13. getline(myfile, line);
  14. ui->QuestionLabel->setText(line.c_str());
  15. qDebug() << "Question: " << line.c_str();
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

quiz.h
Qt Code:
  1. #ifndef QUIZ
  2. #define QUIZ
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7. #include <QDialog>
  8. using namespace std;
  9.  
  10. namespace Ui {
  11. class Quiz;
  12. }
  13.  
  14. class Quiz : public QDialog
  15. {
  16. Q_OBJECT
  17.  
  18. public:
  19. explicit Quiz(QWidget *parent = 0);
  20. ~Quiz();
  21. ifstream myfile;
  22. string line;
  23. void next_question();
  24.  
  25. private:
  26. Ui::Quiz *ui;
  27.  
  28.  
  29. private slots:
  30. void on_NextButton_clicked();
  31. };
To copy to clipboard, switch view to plain text mode 


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.