Terminal screen output difference Windows Linux
-
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? -
@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()
?
- where did you create
-
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.
-
@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?
-
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? -
@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?
-
-
@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;