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 a开发者_如何学Pythonny 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 #ifdef
s 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 QWidget
s, the other one that just does text input/output.
To wrap it up, use an #ifdef
in you main()
to select which "presentation" classes to use (and switch between QCoreApplication
for non-GUI and QApplication
for GUI).
Don't base that #ifdef
on WIN32
, use a custom variable. That way you can run and test both versions in the environment you're more familiar with.
精彩评论