I am working on an simple c++ application for my work that needs to run both on Windows and on Linux. When running on Windows it should display a simple GUI and when running on Linux it should use a textual UI (because the Linux computer don’t use any GUI at all).
I was wondering if I could use Qt to write the app (since its cross platform) and replace the GUI usage on Linux with printouts to STDOUT using “#ifndef WIN32”?
Any other suggestions would be appreciated. The program reads some properties from an xml file and runs some tests according to those properties (access sockets, environmental vars etc.). My goal is to write a single project that would be statically compiled (to get an undependable executable) for each platform and avoid creating different projects.
Thank you.
It’s certainly possible, but try to avoid
#ifdefs as much as possible.One approach is to isolate all the core features (data processing, networking etc…) in non-GUI classes. Then you write two sets of classes for presentation: one based on
QWidgets, the other one that just does text input/output.To wrap it up, use an
#ifdefin youmain()to select which “presentation” classes to use (and switch betweenQCoreApplicationfor non-GUI andQApplicationfor GUI).Don’t base that
#ifdefonWIN32, use a custom variable. That way you can run and test both versions in the environment you’re more familiar with.