PDA

View Full Version : How do I create a default QTextStream?



lni
17th October 2009, 16:06
Hi,

I am creating a function with QTextStream as argument, how do I create a default QTextStream?

I do

void dump( QTextStream& ostr=QTextStream( stdout ) )
{
ostr << "Test" << endl;
}


It complains "error: default argument for ‘QTextStream& str’ has type ‘QTextStream’"

I can do so using STL as:



void dump( std::ostream& ostr=std::cout )
{
ostr << "Test" << std::endl;
}


Any trick? Thanks!

wysota
17th October 2009, 16:19
You can't assign a temporary object to a non-const reference. The STL example uses an object which is not temporary - if you create the default argument outside the declaration it will work with QTextStream too.


QTextStream qOut(stdout);
//...
void dump(QTextStream &stream = qOut) {
...
}

lni
17th October 2009, 16:28
You can't assign a temporary object to a non-const reference. The STL example uses an object which is not temporary - if you create the default argument outside the declaration it will work with QTextStream too.


QTextStream qOut(stdout);
//...
void dump(QTextStream &stream = qOut) {
...
}

Thanks. It would be nice QTextStream has a default object for that purpose....

wysota
17th October 2009, 18:26
Thanks. It would be nice QTextStream has a default object for that purpose....

AFAIR it has. Source code is your friend to find it :)

lni
18th October 2009, 21:03
AFAIR it has. Source code is your friend to find it :)

Mind to tell where it is? I can't find it...thanks

wysota
18th October 2009, 21:36
Mind to tell where it is?

It's probably on your computer if you downloaded Qt yourself. If not, go to the main page of this site and look in the right column of the page or visit qt.nokia.com or qt.gitorious.org