开发者

Qt enaubling GUI on Windows disabling GUI on linux

开发者 https://www.devze.com 2023-03-21 02:51 出处:网络
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 t

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 #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 #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.

0

精彩评论

暂无评论...
验证码 换一张
取 消