Results 1 to 6 of 6

Thread: qDebug Problem

  1. #1
    Join Date
    Nov 2015
    Posts
    67

    Default qDebug Problem

    QString a = "test\n";
    qDebug() << a;

    output of programm is "test\n"

    Why it does not interptret correctly? I cannot write after every QString varaible with a \n in it toLatin1().data() to get an correct output.

    Is there no simple solution in Qt?

    thank you

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qDebug Problem

    qDebug() is doing exactly what you told it to: print the value of the QString variable "a". The value of "a" is a string composed of the letters 't', 'e', 's', 't', '\n'.

    Think about what you are asking for - if qDebug() interpreted non-printing characters like '\t' or '\n', how would you ever be able to print the actual contents of a string that contained those? It's a tool to aid you in debugging, where you can ask it to print the actual contents of built-in types, Qt types, and custom types for which you have implemented the right operator<<().

    qDebug() outputs types with default formatting. If you want qDebug to custom format your output, you can use QTextStream manipulators. qDebug() automatically inserts a newline after ever statement and inserts spaces between arguments separated by <<.

  3. #3
    Join Date
    Nov 2015
    Posts
    67

    Default Re: qDebug Problem

    "qDebug() outputs types with default formatting. If you want qDebug to custom format your output, you can use QTextStream manipulators."

    Can you explain pls?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qDebug Problem

    It is explained in the QDebug and QTextStream documentation. Look for the section on manipulators in the QTextStream docs.

    Try

    Qt Code:
    1. qDebug() << qSetFieldWidth( 8 ) << qSetRealNumberPrecision( 2 ) << 3.14159;
    2. qDebug() << fixed << right << 3.14159;
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Nov 2015
    Posts
    67

    Default Re: qDebug Problem

    thank you_____

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qDebug Problem

    You could also do simpler things like:

    Qt Code:
    1. qDebug() << QString( "%1" ).arg( 3.14159, 8, 'f', 2 );
    To copy to clipboard, switch view to plain text mode 

    which will produce the same output as the first line in the previous reply.

Similar Threads

  1. Problem with QT 4.6 qDebug and QString.
    By weaver4 in forum Newbie
    Replies: 7
    Last Post: 18th March 2013, 12:15
  2. qDebug / qStringList - Problem
    By EMKAH in forum Newbie
    Replies: 5
    Last Post: 19th November 2012, 16:50
  3. using qdebug
    By GrahamLabdon in forum Newbie
    Replies: 2
    Last Post: 3rd February 2011, 09:59
  4. qDebug() on OSX
    By December in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2008, 17:14
  5. qdebug
    By drkbkr in forum Qt Programming
    Replies: 12
    Last Post: 29th September 2006, 15:26

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.