Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Terminal screen output difference Windows Linux
Forum Updated to NodeBB v4.3 + New Features

Terminal screen output difference Windows Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 378 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pixbyte
    wrote on last edited by pixbyte
    #1

    I create a small commandline app and with this app I emulate a progress bar.
    I write first a "base line" to the screen and inside next line I add a "*" to it until
    it is full.

    I have a main thread and a callback.

    it looks like

    #include <QCoreApplication>
    #include <QThread>
    #include <QMutex>
    #include <QDebug>
    #include <iostream>
    
    #if defined (WIN32)
    # define tString std::wstring
    # define tCout std::wcout
    #else
    # define tString std::string
    # define tCout std::cout
    #endif
    
    
    QMutex	g_cOutputLock;
    bool    g_bDone = false;
    tString g_strBuffer2;
    
    void terminalPrinter(QString output)
    {
    #if defined (WIN32)
        tCout << output.toStdWString().c_str() << std::endl;
    #else
        tCout << output.toStdString().c_str() << std::endl;
    #endif
    }
    
    void OnJobDone(void*)
    {
        g_cOutputLock.lock();
        g_bDone = true;
        g_cOutputLock.unlock();
    }
    
    void OnProcess(float fPercent, float, float,
        double, double, void*)
    {
        static int nChars = 0;
        g_cOutputLock.lock();
        while ((fPercent / 100.0) * 80 > nChars)
        {
    
            g_strBuffer2 += _T("*");
            nChars++;
    
        }
        g_cOutputLock.unlock();
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv); 
    
        SetProcessEventCallback(OnProcess, nullptr);
        SetJobDoneEventCallback(OnJobDone, nullptr);
    
        ::Erase(true,true);
    
        terminalPrinter("Burning:");
        terminalPrinter("0%--------------------------------------------------------------------------100%");
    
        for (; !g_bDone;)
        {
            
            QThread::usleep(5);
    
            g_cOutputLock.lock();
            if (!g_strBuffer2.empty())
                {
                tCout << g_strBuffer2;
                g_strBuffer2.clear();
            }
    
            g_cOutputLock.unlock();
        }
    
    terminalPrinter("App ended");
    return 0;
    }
    

    On Windows I get
    0%--------------------------------------------------------------------------100%
    "********* "
    But on Linux I get only a complete line after g_bDone is true
    0%--------------------------------------------------------------------------100%
    "************************************************************************************"
    Someone know such a problem? What is the difference between them?

    KroMignonK 1 Reply Last reply
    0
    • P pixbyte

      I create a small commandline app and with this app I emulate a progress bar.
      I write first a "base line" to the screen and inside next line I add a "*" to it until
      it is full.

      I have a main thread and a callback.

      it looks like

      #include <QCoreApplication>
      #include <QThread>
      #include <QMutex>
      #include <QDebug>
      #include <iostream>
      
      #if defined (WIN32)
      # define tString std::wstring
      # define tCout std::wcout
      #else
      # define tString std::string
      # define tCout std::cout
      #endif
      
      
      QMutex	g_cOutputLock;
      bool    g_bDone = false;
      tString g_strBuffer2;
      
      void terminalPrinter(QString output)
      {
      #if defined (WIN32)
          tCout << output.toStdWString().c_str() << std::endl;
      #else
          tCout << output.toStdString().c_str() << std::endl;
      #endif
      }
      
      void OnJobDone(void*)
      {
          g_cOutputLock.lock();
          g_bDone = true;
          g_cOutputLock.unlock();
      }
      
      void OnProcess(float fPercent, float, float,
          double, double, void*)
      {
          static int nChars = 0;
          g_cOutputLock.lock();
          while ((fPercent / 100.0) * 80 > nChars)
          {
      
              g_strBuffer2 += _T("*");
              nChars++;
      
          }
          g_cOutputLock.unlock();
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv); 
      
          SetProcessEventCallback(OnProcess, nullptr);
          SetJobDoneEventCallback(OnJobDone, nullptr);
      
          ::Erase(true,true);
      
          terminalPrinter("Burning:");
          terminalPrinter("0%--------------------------------------------------------------------------100%");
      
          for (; !g_bDone;)
          {
              
              QThread::usleep(5);
      
              g_cOutputLock.lock();
              if (!g_strBuffer2.empty())
                  {
                  tCout << g_strBuffer2;
                  g_strBuffer2.clear();
              }
      
              g_cOutputLock.unlock();
          }
      
      terminalPrinter("App ended");
      return 0;
      }
      

      On Windows I get
      0%--------------------------------------------------------------------------100%
      "********* "
      But on Linux I get only a complete line after g_bDone is true
      0%--------------------------------------------------------------------------100%
      "************************************************************************************"
      Someone know such a problem? What is the difference between them?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @pixbyte Your code looks strange to me.

      If it is a Qt application:

      • where did you create QCoreApplication? It should be the first thing to do in main()
      • what is terminalPrinter()?
      • what is SetProcessEventCallback()?
      • what is SetJobDoneEventCallback()?

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pixbyte
        wrote on last edited by
        #3

        Sorry, I have added the missing information.

        SetProcessEventCallback(OnProcess, nullptr);
        SetJobDoneEventCallback(OnJobDone, nullptr);

        This I set to an external Library, that will call the given functions on an own event
        or if it is ready.

        Not to forget, the app is functional doing what it have to do, it is just the interaction with the terminal windows that is different on Windows and Linux.

        KroMignonK 1 Reply Last reply
        0
        • P pixbyte

          Sorry, I have added the missing information.

          SetProcessEventCallback(OnProcess, nullptr);
          SetJobDoneEventCallback(OnJobDone, nullptr);

          This I set to an external Library, that will call the given functions on an own event
          or if it is ready.

          Not to forget, the app is functional doing what it have to do, it is just the interaction with the terminal windows that is different on Windows and Linux.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by KroMignon
          #4

          @pixbyte said in Terminal screen output difference Windows Linux:

          it is just the interaction with the terminal windows that is different on Windows and Linux.

          Maybe, but as you are not using Qt functions to write on terminal, what is the link with Qt?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pixbyte
            wrote on last edited by pixbyte
            #5

            The app is written with the QT Framework and it works different on Windows and Linux.
            The app is compiled inside the QTCreator (Where the sceleton was created).
            And QT is not a programming language, it is a Framework. My app is written with QT Framework in C++.
            If this is not qualified for an question about QT then please let me know what is allowed?

            KroMignonK 2 Replies Last reply
            0
            • P pixbyte

              The app is written with the QT Framework and it works different on Windows and Linux.
              The app is compiled inside the QTCreator (Where the sceleton was created).
              And QT is not a programming language, it is a Framework. My app is written with QT Framework in C++.
              If this is not qualified for an question about QT then please let me know what is allowed?

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by KroMignon
              #6

              @pixbyte said in Terminal screen output difference Windows Linux:

              The app is written with the QT Framework and it works different on Windows and Linux.
              The app is compiled inside the QTCreator (Where the sceleton was created).
              And QT is not a programming language, it is a Framework. My app is written with QT Framework in C++.
              If this is not qualified for an question about QT then please let me know what is allowed?

              Sorry, perhaps my reply is too short.
              I don't want to hurt you. It is not easy to write down clearly, even more when english is not my first language!

              I know that Qt is a C++ framework and not a programming language.
              And Qt Creator is just an IDE. You can use Qt Creator to develop any kind of application, without have to use Qt framework.

              What I want to say, starting with my first post:

              • If your application is a Qt based console app, you have to create QCoreApplication instance, at begin. It should be the first thing to do in your main (cf. https://doc.qt.io/qt-5/qcoreapplication.html#details). You don't have do it. That's not good for a Qt based application.

              • To write on console, you are using your own functions, not Qt based functions (like qDebug() and so on). So without showing how you write the progress base on console, how should you got help?

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              1
              • P pixbyte

                The app is written with the QT Framework and it works different on Windows and Linux.
                The app is compiled inside the QTCreator (Where the sceleton was created).
                And QT is not a programming language, it is a Framework. My app is written with QT Framework in C++.
                If this is not qualified for an question about QT then please let me know what is allowed?

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #7

                @pixbyte Just to complete my previous reply.

                If you are using Qt, why not using Qt facilities to write message on console?

                For example with QTextStream:

                inline QTextStream& qStdout()
                {
                    static QTextStream r{stdout};
                    return r;
                }
                
                ...
                
                foreach(QString x, strings)
                    qStdout() << x << endl;
                

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved