Limitation of string length for qDebug() output?


  • Moderators

    The output of strings to qDebug() is limited to 1023 characters. Does this make sense?

    I am checking with some print routines. Typically I am writing to a std::ostringstream and very often I am writing this string later on to a file. Respectively I am using qDebug() for display.

    This time the output of the routine is a bit longer about 1800 byte. qDebug() prints the characters correctly up to character 1023 and afterwards some random bytes are showing up. The output holds a couple of linefeed to make a nice output. There are already several before the "magic" limit.

    ostringstream ostrc;
    gen7.print( cout );
    gen7.print( ostrc );
    qDebug() << "String length " << ostrc.str().length();
    QString qstr ( ostrc.str().c_str() );
    qDebug() << qstr;
    qDebug() << ostrc.str().c_str();
    

    When running in the debugger the print to cout is shown correctly in Application output pane. The outputs based on QString and directly from the ostringstream show the behaviour. I have checked the qstr ist correctly filled with 1800 something bytes. Nothing special shown in the debugger around 1023. Therefore, I assume this is a speciality of qDebug().


  • Lifetime Qt Champion

    Hi,

    Maybe a silly question but aren't you seeing the escaped version of the linefeed characters you are using ?


  • Moderators

    @SGaist

    No, I do not.

    The text is shown as it would be in a text file written to with the print routines.


  • Moderators

    Digging a bit deeper I have found another reason.
    Creating a small example case:

    #include <QCoreApplication>
    
    #include <QDebug>
    #include <sstream>
    #include <iomanip>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        std::ostringstream ostr;
    
        for ( unsigned i = 0; i < 120; ++i )
            ostr << std:: setw( 10 ) << i << std::endl;
    
        qDebug() << ostr.str().c_str();
    
        return 0;
    }
    

    In the application output pane this shown:

    Debugging starts
             0
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            36
            37
            38
            39
            40
            41
            42
            43
            44
            45
            46
            47
            48
            49
            50
            51
            52
            53
            54
            55
            56
            57
            58
            59
            60
            61
            62
            63
            64
            65
            66
            67
            68
            69
            70
            71
            72
            73
            74
            75
            76
            77
            78
            79
            80
            81
            82
            83
            84
            85
            86
            87
            88
            89
            90
            91
            92
     ‘Ø7kDebugging has finished
    

    Actually it is showing 2 Japanese or Chinese style characters which are not shown here. However, that is not the point anyway.

    At first I had run the small application in terminal mode. The problem does NOT appear in terminal output. It is limited to the output pane of Qt creator.

    Therefore the focus shifts to Qt creator. Which is version 4.0.3 on windows 10 (64bit).
    The tests were done with Qt 5.4.2 and Qt 5.7.0 precompiled libs and tools as required.


  • Moderators

    I have updated Qt creator to 4.1.0 and the bahviour is still there.
    Bug report on JIRA created QTCREATORBUG-17117


  • Moderators

    @SGaist

    I think you are referring to this closed bug report QTBUG-50722.
    Luckily I have used Qt lib versions navigating around this bug ;)
    Neither Qt5.4.2 nor Qt5.7.0 does show this.


  • Lifetime Qt Champion

    Thanks for the report !

    I was thinking more about QTBUG-47316.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.