Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
GUI app print to console
I am creating app with GUI (widgets) for Linux. If you run my app it shows GUI (widget), but I want to make my app to be available for console only Linux too (without desktop environment).
So is possible that if someone runs my app through console it will not shows GUI (because you can't) but instead of that I will outputs some text into console?
yes, its possible.
Doc has sample.
The trick is to use QCoreApplication instead of QApplication and
a parameter telling when to run non gui.
But for this to work as intended, you must design your app
so any data it needs or function do not
live in mainwindow or other widgets.
Then your app can work in both modes.
Thank you very much, sorry for late reply, just one more question this is only one way?
Or is possible that program will detect if it is run from command line or just by arguments like:
Well it uses the parameter to know, so it needs some flag in some form or another.
I have not seen other methods, but some could exists involving navtive api calls
to find out if run from a shell or via other means of activation.
Thank you and does have Qt access to some of these API calls? Or it must be done in pure C++?
Qt is pure c++. :)
But there would not be a Qt class for it.
You would use native windows / linux apis
something like shown here
Thank you :) I consider Qt as framework for C++ :) By pure C++ I meant code without Qt classes :)
ok, well it would be ok fine to do in a Qt app.
but its not crossplatform.
t0msk last edited by t0msk
@mrjj I think it could be cross platform, if I added support for Linux, Windows and Mac like:
#ifdef __linux__ //linux code goes here #elif _WIN32 //windows code goes here #else #endif
Yes, that's the normal way to have different code for
each platform since same calls wont work.
So if you wrap it up in a nice class, and add code for each platform
it will be crossplatform :)
Qt already provides macros for the OS it supports. See here.