setText using a string read from file
Hi all, I hope this is an easy question. How do I go about solving this problem I have with setText
This is my code:
Code:
string line;
ifstream myfile("example.txt");
if (myfile.is_open()) // Checks to see whether myfile opens
{
getline(myfile, line);
ui->QuestionBox->setText(line);
} else ui->QuestionBox->setText("An error has occured!");
It keeps throwing up an error. Is this because setText is supposed to have a QString associated with it... if so how do i overcome this problem. C++ didn't confuse me until I started learning QT, now nothing seems to work :(
Thanks for your help
Re: setText using a string read from file
Quote:
Originally Posted by
Splatify
It keeps throwing up an error. Is this because setText is supposed to have a QString associated with it...
Try it, test it, ...
But I think you're on to something ;-)
Quote:
if so how do i overcome this problem.
Use a QString. See the documentation.
Quote:
C++ didn't confuse me until I started learning QT, now nothing seems to work :(
Then you still have things to learn. Qt doesn't change how you use C++, it's just a collection of classes. The only thing extra is an extra precompiler for the signals and slots.
Re: setText using a string read from file
Hi I have solved my problem now :)
Thanks for the help... I think. :/
It was very easy. I just converted the string to QString using
Thanks very much :)
Re: setText using a string read from file
Quote:
Originally Posted by
Splatify
I just converted the string to QString using
c_str() returns a QString?