简体   繁体   中英

Running a terminal via QT

I am a beginner is C++. I am trying to find, is it possible to run my program in both in QT window and Linux based. When the user logins into my system, the user can select GUI or terminal mode to run the system.

Thus, I would like to know is it possible to do it. If possible how can I proceed on? What command should I use to switch from a QT window to a terminal? Do I need to create a separate set of project for both individually or using the same set of classes?

All Linux programs (unless explicitly disabled) print out text to a terminal. If you run the program in a graphical environment you will probably not run it from a console, therefore you won't see the output, but it will be still there.

If you want your program to be usable from a console, just test whether you could create the main window and if not, fallback to simple text output.

Note that the binary will still require the X server and Qt libraries to be installed.

You can construct your application with or without the GUI enabled through the QApplication constructor. Consult the example in Qt's documentation:

http://qt-project.org/doc/qt-4.8/qapplication.html#QApplication-2

Though, it should be noted that everything in Let_Me_Be's response is correct . In fact, the Qt example does exactly what he's suggesting. Please take the time to understand his answer before you plunge into coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM