Results 1 to 6 of 6

Thread: How do I create a default QTextStream?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How do I create a default QTextStream?

    Hi,

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

    I do
    Qt Code:
    1. void dump( QTextStream& ostr=QTextStream( stdout ) )
    2. {
    3. ostr << "Test" << endl;
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    I can do so using STL as:

    Qt Code:
    1. void dump( std::ostream& ostr=std::cout )
    2. {
    3. ostr << "Test" << std::endl;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Any trick? Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I create a default QTextStream?

    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.

    Qt Code:
    1. QTextStream qOut(stdout);
    2. //...
    3. void dump(QTextStream &stream = qOut) {
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I create a default QTextStream?

    Quote Originally Posted by wysota View Post
    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.

    Qt Code:
    1. QTextStream qOut(stdout);
    2. //...
    3. void dump(QTextStream &stream = qOut) {
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    Thanks. It would be nice QTextStream has a default object for that purpose....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I create a default QTextStream?

    Quote Originally Posted by lni View Post
    Thanks. It would be nice QTextStream has a default object for that purpose....
    AFAIR it has. Source code is your friend to find it
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I create a default QTextStream?

    Quote Originally Posted by wysota View Post
    AFAIR it has. Source code is your friend to find it
    Mind to tell where it is? I can't find it...thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I create a default QTextStream?

    Quote Originally Posted by lni View Post
    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
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Eclipse debugging: Unable to create variable object
    By PUK_999 in forum Installation and Deployment
    Replies: 0
    Last Post: 20th August 2009, 21:42
  2. Replies: 6
    Last Post: 8th July 2009, 20:28
  3. Replies: 5
    Last Post: 27th May 2009, 12:49
  4. Cannot create MySQL stored procedure / views from Qt
    By pshah.mumbai in forum Qt Programming
    Replies: 8
    Last Post: 8th October 2008, 16:22
  5. Create QTextStream
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2007, 20:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.