Results 1 to 4 of 4

Thread: qDebug - how to avoid CRCL (newline character)?

  1. #1
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default qDebug - how to avoid CRCL (newline character)?

    Hello!

    I'd like to output vector to the qDebug in QT Creator. Unfortunately every number is in separated line. How can I avoid it?

    If I execute similar code and output vector of vectors, the result looks as follows:
    (1,2,3)
    (2,4,6)

    But if I do similar thing, i.e. only vector, I receive every number of the vector in separate line. I don't want qDebug to put characters of new line at the end of every execution. In order to avoid this, I have tried several different things but I haven't succeeded. I have either every number in separated line or build error (the third option is just no output in qDebug).

    The code looks as follows:

    Qt Code:
    1. //***** TESTING: SHOW DISTANCES AND WEIGHTS *****
    2.  
    3. //the version below works but everything is in separated line (with only zero digit in every of them)
    4. QList<int>::iterator it2 = distances.begin();
    5. qDebug() << "distances: " << *it2;
    6. //the line below should do the same what the line above (without new line characters) but it does not work
    7. //fprintf (stderr, "%s ", *it2);
    8. //the line above was found here http://lists.trolltech.com/qt-interest/2005-11/thread00923-0.html
    9.  
    10. //the version below don't work; it was expected to write single line (0,0,0,...)
    11. //QList< QList<int> >::iterator it2 = distances.begin();
    12. //for( ; it2 != distances.end(); ++it2 )
    13. // qDebug() << *it2 << " ";
    14.  
    15. //***********************************************
    To copy to clipboard, switch view to plain text mode 

    Regards!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qDebug - how to avoid CRCL (newline character)?

    I guess the easiest way (but far not the best or the only one) is to append first all the strings in to one string, and output only that string with one qDebug() call.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    johnyjj2 (12th January 2011)

  4. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: qDebug - how to avoid CRCL (newline character)?

    How about:
    Qt Code:
    1. qDebug() << distances;
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to norobro for this useful post:

    johnyjj2 (12th January 2011)

  6. #4
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qDebug - how to avoid CRCL (newline character)?

    Thanks!

    1. What if I have got several different things which I'd like to output to qDebug? Those are in different parts of the code but are short enough to be stored in one single line. In other words, is there any way to write "qDebug << backspace_character" in order to delete CR/CL characters of new line?

    2. And the second question, more connected with object-oriented programming. I've got files created automatically by QT Creator: main.cpp, mainwindow.h, mainwindow.cpp. There are also files which I have added: mydata.h, mydata.cpp. In the file mydata.cpp I have function breadth() for breadth search algorithm. I use qDebug() inside this breadth() function. However I use it many times in different places of the code. What if I wanted to use one function, e.g. showDebugInfo(variables which are declared inside the breadth function to be given by reference) and call it inside breadth() function? I mean, where should I declare this showDebugInfo(...) function? (Because it would be like function called from inside the function which is method of the class - it makes me confused). And how to give those other variables as reference to that function? I've got such a code at this moment:

    Qt Code:
    1. qDebug() << "Value of n = " << n;
    2. qDebug() << "distances: " << distances;
    3. //...
    To copy to clipboard, switch view to plain text mode 

    where distances is QList<int> distances; and there are more lists like this in my qDebug part of the code.

    Regards!
    Last edited by johnyjj2; 16th January 2011 at 10:17.

Similar Threads

  1. about newline
    By drizzlefsh in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2009, 18:21
  2. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  3. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25
  4. QTextBrowser NewLine
    By QbelcorT in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2009, 08:34
  5. Windows newline
    By indifference in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2007, 01:34

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.