Issue with getting a QString output through a function
Hi
I have a problem where I can't seem to get a output to display in a console when doing it through a function.
It works when doing it through Main(), but just blank when doing it through the function.
Below is some of my code:
Code:
//Main()
#include "ConferencePaper.h"
#include "JournalArticle.h"
#include "Reference.h"
#include <QDebug>
#include <QTextStream>
int main()
{
//QApplication app(argc, argv);
list1 << "This is a test";
Reference a("Marius",list1,1,"c"); //Instance of the Reference class created with parameter values
cout << "Title: " << a.getTitle(); //This works fine
a.toString();
return 0;
}
//Reference Function
Code:
#include <QString>
#include <QStringList>
#include <QTextStream>
#include "Reference.h"
{
return QString("Title: %1\n") .
arg(getTitle
());
//Does not display anything
}
Thanks
Re: Issue with getting a QString output through a function
Reference::toString() does not print anything; it just builds and returns a QString. The call
in main() therefore builds a QString and throws it away immediately. What you probably intended was to print the QString returned by the call, as in:
Code:
cout << a.toString();
If I were you I would choose another name for the QTextStream; readers of your code will assume cout refers to std::cout.