 Hey, everybody, it's Brian. And in this video, we're going to talk about determining the operating system both at compile time and at runtime. They don't really talk about this very much in depth in most classes. And I'm always mystified by this because Qt runs anywhere and there are times where, well, you'll need to run different code depending on what operating system you're on. So let's dive in and take a look. All right, our first stop here is going to be the Qt global or the global declarations. And this gets really scary when you look at it here. So what's really happening is this is the global. This is everything that's available to every Q application. And if you start scrolling down, not a lot of this really makes a lot of sense when you look at it. But we're going to keep going down and down until you see Q underscore OS and then you start seeing familiar names, Android, BSD for iOS Linux. That's right. This is all built in. For example, I'm on Linux. So if I click this, it says it's defined on Linux. That's right. These are preprocessor directives you get at compile time. So for example, if I say QOS Mac, you'll see it's deprecated. And you should not use this. This is where it gets a little confusing. There's a Mac and a Mac OS, which is defined on Mac OS, but Mac is something you shouldn't use. Short version, you're going to have to dig through the documentation to figure out your specific use case. But anything that starts with Q underscore OS is available for you to try to use. Now, I say try. And here's why. For example, if you're on Mac OS, when 64 is not going to be defined, because it's only defined on 64 bit versions of windows, you kind of get what's going on here. So let's take a look at some code. We've got our little compile time function here. And I'm going to do one typing it. And then the rest I'm just going to probably copy and paste just to save time. So we're going to say if def, which is short for if defined. And then we want Q underscore OS. And you see right there is Q underscore OS Linux because I'm on Linux, but Unix is also declared. That's why you got to be a little bit careful about what you're doing. And then we're going to go ahead and do an and f. And from there, it becomes ridiculously simple. I'm going to say Q info. Hello from Linux. It's really that simple. And you can just take this and copy and paste it. And let's just jump back in and see what we're looking for here. So all right, so QOS windows, which is a synonym for QOS when defined all supported versions of windows, and you can also get a 32 or 64 bit. So let's just grab this. I'm going to do the old copy and paste maybe if it lets me let back to our virtual machine and put it in there. Notice how it's automatically grayed out. Because it's not defined. We're saying if defined. And this is not defined because I'm on a Linux machine. If I was on windows, you'd see the polar opposite where this would be highlighted. And this would be grayed out. You can actually take this to some extreme if you really wanted to. And I'm just going to do the magic of copy and paste here. Maybe it's time for a new mouse. This thing doesn't want to agree with me here. There we go. So I've kind of done something here that is well, a monstrosity, but you'll see this out in the real world. You have if defined Mac OS, this is a Mac Linux windows and you can see because I'm on Linux, the other parts are grayed out. They just simply won't run. We can save and run this and see exactly what happens. Because I'm on Linux, it's going to simply say this is Linux. Now if you were to take that same code and run it on, say a Mac, it'll say this is Mac. If you take that same code and run it on Windows, it'll say this is Windows. But then it'll tell you whether it's 32 or 64 bit. All right, sometimes you need a little bit more info. And that's where the Qsys of full class comes in. The Qsys of full class provides information about the system. I love that description because this class does exactly what it says it does. If we scroll down, you can see there are static public members. That's right static. You don't even have to create an instance of this. I will just for demonstration, but you don't have to. But you can get like the boot unique ID, the build a bi CPU architecture, the current CPU architecture kernel type kernel version, hostname. And I'm kind of flying through these most of these you won't actually ever really need. But this is what I love about their documentation. If you're ever curious what something is, for example, build a bi, it has more information than you'll probably ever need to know unless you're really deep diving into this for some unknown reason. So how does this work? Well, let's take a look. I'm going to type out a little bit and then I'm just going to copy and paste just to save some time. So I'm gonna say Qsys info. Again, you don't have to make an instance. But I'm going to call this info. I'm gonna say Q info. Let's go ahead and let's print out the pretty product name, which is basically just a human readable version. This is something you put in like an about box or something like that. And I'm gonna say info dot pretty product name. Again, you can do this using the static, you don't have to make an instance, but it just works. So one thing you'll notice right off the bat is this is at runtime, we're not using the pre processor symbols. So let's go ahead and run this and see what it says. This is Linux and the pretty product name is Linux mint 20. Yes, this is pretty awesome. It just works. You don't have to really do any sort of mysticism or API calls or figure out some black magic incantation at three in the morning. So let's just copy and paste this out just to save a smidge of time. We're gonna get the pretty product name, the product type version machine host name. If you ever need that, this is a super simple way of getting it machine unique ID. Again, if you ever need it, it's right there. Current CPU architecture and the build CPU architecture. And then the build a bi, let's go ahead and say run. Again, this is probably way more information than you'll ever need about your system for most applications, but it's there if you need it. So on this virtual machine, this is Linux, the pretty product name is Linux met 20 product type Linux mint product version 20, you guessed it. The pretty product name is pretty much just a beautified version of type and version. There's my machine host name, you see this is on virtual box. And the unique ID in case I ever need that. Current CPU architectures x 86 64. So is the build and the build a bi is x 86 64 little edian dash LP 64. And if you have no idea what that means, of course, you can dive into the help system and read all about it. I hope you enjoyed this video, you can find the source code out on github.com. If you need additional help, myself and thousands of other developers are hanging out in the void realms Facebook group. This is a large group with lots of developers and we talk about everything technology related not just the technology that you just watched. And if you want official training, I do develop courses out on you to me.com. This is official classroom style training. If you go out there and the course you're looking for is just simply not there. Drop me a note, I'm either working on it or I will actually develop it. I will put a link down below for all three of those. And as always, help me help you smash that like and subscribe button. The more popular these videos become the more I'll create and publish out on YouTube. Thank you for watching.