Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Unordered output in application output panel of Qt Creator



  • Qt 5.7 - Qt Creator 4.1.0 - MinGW 5.3 and VC++ 2015 - Windows 10 64-bits

    I get unordered output of my core application in the application output panel of Qt creator. If I define a console application, the output in the console is correct. See picture attached, where you can see the console output and the output panel of Qt Creator.
    Notice that I have this behaviour with both compilers mentioned above.
    Why is the output in the output panel not ordered? The application is running in one thread, see attached source code of main.

    // main.cpp
    
    #include <QCoreApplication>
    #include <QDebug>
    #include <iostream>
    #include "blumblumshub.h"
    #include "../../qutil/qutil.h"
    #include "../../benchmark/benchmark.h"
    #include "../../mersenne/mersenne/mersenne.h"
    
    using namespace std;
    bool BENCHMARK = true;
    
    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
    
        qDebug() << "sizeof(int):" << sizeof(int) << "  sizeof(void*):" << sizeof(void*);
    
        qDebug() << "\n=== testing BBS ===";
        int P = 7;
        int Q = 19;
        int seed = 4;
        qDebug() << "p:" << P << "   q:" << Q << "   seed:" << seed;
    
        BBS numberGen(P, Q, seed);
    
        //generate 10 random numbers
        for (int i = 0; i < 10; i++)
        {
            cout << numberGen.getRandNum() << " ";
        }
        cout << endl;
    
        //generate 10 random bits
        for (int i = 0; i < 10; i++)
        {
            cout << numberGen.getRandBit() << " ";
        }
        cout << endl;
    
        ///////////////////////////////////////////////////////////////////////////
    
        P = 1;
        Q = 100;
        seed = 1;
        qDebug() << "\n=== testing blumblumshub ===";
        BlumBlumShub generator( P, Q, seed );
        //generate 10 random numbers
        for (int i = 0; i < 10; i++)
            cout << generator.getNum() << " ";
        cout << endl;
    
        //generate 10 random bits
        for (int i = 0; i < 10; i++)
            cout << generator.getBit() << " ";
        cout << endl;
    
        //--------------------------------- 64 bits -------------------------------
    
        qDebug() << "\n=== testing blumblumshub 64 bits ===";
        BlumBlumShub64 generator64( P, Q, seed );
    
        //generate 10 random numbers
        for (int i = 0; i < 10; i++)
            cout << generator64.getNum() << " ";
        cout << endl;
    
        //generate 10 random bits
        for (int i = 0; i < 10; i++)
            cout << generator64.getBit() << " ";
        cout << endl;
    
        // ----- with big data now ------
        qDebug() << "----- testing big numbers -----";
        generator64.setParams(123456789, 2345678, 3456789);
    
        //generate 10 random numbers
        for (int i = 0; i < 10; i++)
            cout << generator64.getNum() << " ";
        cout << endl;
    
        //generate 10 random bits
        for (int i = 0; i < 10; i++)
            cout << generator64.getBit() << " ";
        cout << endl;
    
        // benchmark
    
        unsigned loops = 100000;
        uint32_t sum32 = 0;
        uint64_t sum64 = 0;
        Mersenne mersenne(123);
        Mersenne64 mersenne64(123);
    
        Benchmark bm;
        bm.init();
    
        for ( unsigned i = 0; i < loops; ++i )
            sum32 += generator.getNum();
        bm.getMark( "blumblumshub" );
    
        for ( unsigned i = 0; i < loops; ++i )
            sum64 += generator64.getNum();
        bm.getMark( "blumblumshub64" );
    
        for ( unsigned i = 0; i < loops; ++i )
            sum32 += mersenne();
        bm.getMark( "mersenne" );
    
        for ( unsigned i = 0; i < loops; ++i )
            sum64 += mersenne64();
        bm.getMark( "mersenne64" );
    
    
        QString title = compilerInfo() + "\n - output of " + numberWithThousandsSeparator(loops) + " random numbers -";
        bm.dump( title, false);
    
    
        return app.exec();
    }
    
    ![blumblumshub_output.png](https://ddgobkiprc33d.cloudfront.net/ec0bc96c-1f4f-45ee-ad34-b2cd6a18bf1f.png)

  • Lifetime Qt Champion

    Hi @alainstgt,

    it seems you mix qDebug and cout. Both might use buffering, so the output is interleaved in Creator. The same can happen if you have output to both stdout and stderr.

    Regards



  • @aha_1980
    Thanks for your hint.
    cout still doesn't work correctly, even when not mixed with qDebug(), see picture attached
    blumblumshub_cout.png


Log in to reply