I'm using Qt for a Bluetooth class on Windows, which links to ws2_32.lib, and includes winsock2.h, ws2bth.h, BluetoothAPIs.h. However, I wanna also run this Qt source project on OS X, I know I have to change some source code to make it compatible to OS X, but I don't have a clue on where to start with, can this be achieved by just minor modifications? or it’s necessary to start from scratch? Thanks in advance!
The QtBluetooth module currently supports Android, BlackBerry 10 and Linux (Bluez 4.x) and indeed, OS X and Windows are not supported yet.
You should write the bluetooth functionality you need in XCode and then import it into your Qt project as a linked library. You can also have a library in which you use platform specific macros like #ifdef Q_OS_WIN and #ifdef q_os_osx and put your platform specific code in relevant defs.
Related
When I was using pyqt it was necessary to compile for mac on a mac, instead of being able to export a build for mac from linux (or windows, or whatever)
Now that I'm using straight c++ development, does this fact change at all? Or must I still compile for a given OS on the given OS?
Ideally I'd love to be able to just pick a platform and compile for it. Unity3d does this, but I imagine I'm comparing apples and oranges at this point.
Is this possible? Or do I got to find a friend with a mac? Cuz I don't have no friends... ;)
Typically yes, you have to. In some cases you can cross-compile, for example, this is available stock for android apps, as there is no Qt SDK that can run on android cross-compilation is the only option. You can also build a custom Qt to cross-compile to another OS. This is not available by default, it requires a custom build.
However, when it comes to ios or macos cross-compilation is not an option, as far as I know there is no way around but to compile under macos.
I'm attempting to use Visual C++ cross platform features to write an SDL 2 app for Windows, Windows Universal, iOS, Android and Linux. I have one project for each platform now I want to abstract the SDL stuff to a common project that each platform project will reference with each project supplying the appropriate SDL libs for the platform through the linker.
Is there a project type in VS that actually allows me to do this? I was hoping the shared items project would do the trick, but I doubt thats the one. There does appear to be some form of shared library for iOS and Android, but it doesn't look like that extends to Linux and Win32.
Thanks,
To make a successful cross-platform application with SDL2, you should, in first place, use a compiler that's available on both platform. Because, you will need to compile a binary for each platform. SDL2 seems to support IOS and Android out of the box, but I don't know how deployment is done for the mobile OS. You can still use Visual Studio with CMake or a Makefile and use another compiler instead of Visual C++ to support a cross-platform build, like g++ (mingw32 on windows) or Clang.
This is my first blog or question.
I want to develop platform abstract layer(PLA) for mobile app using c++. i.e from mobile app I could able to talk to bluetooth device without bothering which is underlying OS (i.e IOS ANDROID etc) running. So, I need to discover which OS is running whether IOS or ANDROID using c++ code but without calling native API of any OS.
So, could anybody suggest your thought for the same how we can determine the OS type (ie, IOS, ANDROID) and OS version using c++ code.
To develop which IDE would be preferred to develop c++ code?
Thanks in advance..!!
Thanks,
Raju.
Even if you're developing cross platform code, when the time to compile it comes, you need to target a platform. Determining it is then a matter of checking precompiler definitions.
Most compiler will define some platform while compiling, if not, you can do so by yourself when configuring your project.
For example, Xcode will define __APPLE__ and TARGET_OS_IPHONE and TARGET_OS_MAC when compiling respectively iOS and Mac projects.
For Android, __ANDROID__ should be defined by the toolchain however I've seen multiple mk files add explicit platform flags like so:
LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS)
It is then a matter of using precompilation conditions:
#ifdef __APPLE__
#if TARGET_OS_IPHONE
// Configure for iPhone
#endif
#endif
#ifdef ANDROID
// Configure for Android
#endif
For determining the version, there isn't really anyway to do that without calling Native API. Fortunately, there is pattern you can use to factor out the specific implementation and put a generic interface in front of this code.
As far as IDE, this is largely a matter of choice and availability. Most popular ones are Xcode for iOS and Eclipse for Android but it is possible to use other as well.
I have a C++ eclipse project that I would like to easily compile In Windows and OSX.
The project is currently using an automatically generated makefile.
The libraries that I need vary depending on the platform.
In osx I'm using the CoreMidi, CoreAudio, and CoreFoundation frameworks.
In Windows I'm using the winmm.lib and multithreaded libraries.
What's the simplest way to link different libraries/frameworks depending on the current platform?
I'm currently using the gcc toolchain on OSX. Should I start using the cross compile toolchain?
Should I have two projects. One for working in windows, and one for osx, checking them both in to version control?
Should I write a custom makefile instead of using the automatically generated option that has different g++ arguments depending on the platform?
I personally had the same goal for a project and came to the conclusion the Qt framework was the best thing for me. It handles multiple languages, unicode strings, XML, network communications, native looking user interfaces, console applications: it can do an AWFUL lot.
However, as Paul pointed out, you really have to plan it from the start.
Qt does a good job of abstracting the platform away (in a module called QtCore) allowing you to write vanilla C++ code, or you can chose to include some Qt C++ language extensions which a Qt helper application called the moc (meta object compiler) creates vanilla C++ from, which can then be compiled by most common C++ compilers.
It also has a nifty cross-platform makefile generator called qmake which works on project files to create normal make files for the platform its running on.
Off the top of my head at least Windows XP & 7, OSX 10.4, 10.5, 10.6 are supported currently. But note that OSX Lion is (as of writing) not officially supported but I suspect it will be in the next release.
Based on your description, I am not sure you can easily make it cross-platform. Even without using third-party library, you have to provide separate code for osx and windows. Most of time, they design the system as cross-platform first. It's really hard to make an existing project on single-platform to cross-one. If you have the cross-platform requirement, you'd better design in that way first and rewrite from scratch.
Even though Eclipse can run fine on both OS X and Windows, it is not designed to be used in this way.
The best way to do it is to use separate IDE projects for each platform. This this is the easiest way to have unique compilation settings for multiple platforms.
Yes, you can use two eclipse projects. Alternatively, it's not unusual to have a X-Code project for OSX, and a Visual Studio Project for MS Windows.
I love that Qt is cross-platform but I want to make an application that will call into some Windows specific .dll's. Kinda like Google Chrome does with the glass on Windows Vista/7 (I know Chrome isn't written using the Qt framework just thought it was a good example).
How can I do this in Qt? Is it feasible?
Yes, this is no problem. You just go ahead and do it! Qt itself is just a DLL you call into, it just happens to be the same across different platforms. Just link against the DLLs you like and call them.
There is nothing wrong with using Qt to make a Windows-only application if you like.
As long as you have the relevant Windows SDK headers to hand, and can link with the appropriate libs, then it is easy to mix and match Qt and Win32 code. I use Qt Creator for C++ development which ships with MinGW and includes all the most common Win32 SDK headers and libs. You can even wrap the Windows specific parts of your code with suitable #ifdefs in case you ever come to build for a different platform, e.g.:
#ifdef Q_OS_WIN
#include <windows.h>
void someWindowsSpecificFunc()
{
...
}
#endif // Q_OS_WIN
You can of course call WinAPI functions directly from your Qt code, then it's better to include qt_windows.h not windows.h.
If you just want to add the cool new Windows 7 features to your application then you are better of using a dedicated Qt add-on. There is one called Q7Goodies.
Fearlessly go ahead an write your Win-specific app. You can utilize all the Windows DLLs you want. In this sense, Qt has no limitations. You will still be gaining the advantages of those nifty Qt layout components and customizable skinning. In terms of skinning there is no better framework that Qt. Your users will love all the resizable dialogs you provide them with.