1. 程式人生 > >Going the distance with cross platform development

Going the distance with cross platform development

Platform specificity

This is only scratching the surface of Qt and what it can do for mobile and desktop applications. You will have lots of questions on how to implement functionality and adapting to each platform.

The UI is consistent for each platform; however your C++ code might not be.

By using a combination of Qt specific headers and platform macros, you can address most platform quirks inline with your code. Qt will compile your application to native code taking into account these macros.

The Qt specific libraries also ensures lower level compatibility with the platform’s specific c++ implementation; a detail you generally don’t need to worry about. (Can you imagine knowing how to specifically implement bluetooth functionality for each platform? Thank you Qt for doing this for us.)

Qt 5.11.1 reference documentation, deviceinfo.cpp Example File

There might be times that you want to include platform specific code such as Objective-C code when you compile for iOS or control the property list from within you Qt project. You can do so.

You can specify the objective C headers and sources from within the .pro file, as well as the plist, icons, assets, and build configuration settings. You can essentially include all the information upfront to generate an Xcode project the way you want and compiling the application without having to take foot step into Xcode. It is entirely possible to dynamically generate, build and ship within an continuous integration pipeline like

Jenkins and Fastlane.

Now what? Where can I find more information?

Specifically on Qt

Packt’s Qt 5 eBooksI find these books get down to what you should know very quickly. There is a free trail of 14 days but even buying one of the eBooks or subscribing for a month will save you time getting up to speed.

What else you need to know

I would highly recommend brushing up on C++, (C11 is good enough), so you have the concepts of headers, sources, classes, memory management, pointers, references, macros, and general c++ syntax; and you take advantage of the improvements of C++ such as auto initializers. I’m originally a C# developer and made this transition within a week. If you’re an objective-c developer, these concepts would be a refresher.

If you are completely new to C++, here’s a few resources to start you out:

If you are developing for mobile, you should be familiar with how iOS and Android applications are made and the capabilities and restrictions of that platform. Just because you can build a specific program in Qt and works on your PC, doesn’t mean those APIs are accessible on the platform, e.g. file access might be slightly different between Windows and iOS; or running a tcp server would likely be rejected by Apple if you submit that app to the app store.

Conclusion

There is no perfect solution for everyone and given your use case, needing a complete cross platform framework might not be necessary. I’ve had a recent project where we needed to support essentially all platforms including Windows 7. It is an investment in understanding how each cross platform framework works, and once you make and overcome that initial investment to get walking, then running along adding functionality which makes implementing the same feature for n platforms much easier, cost effective and higher quality.

If you are a Qt developer, feel free to share your own experiences and advice for new Qt developers.

(Note, since technology changes all the time, if there’s anything above is inaccurate, let me know and I’ll update the story.)

Happy cross platform coding!