 Everybody, it's Brian. And in the last video, we covered the queue string, which is a UTF-16 string. In this video, we're going to cover the queue string view class. I mentioned queue string because this really builds upon what we've already learned. Now, queue string view leads to a lot of confusion because it's fairly new. It's only existed since Qt 5.10. So a lot of people go, what is this thing? I don't understand it. The thing I love about queue is, well, its naming convention is very intuitive. Anything that starts with a queue, denote its part of queue, and then it just tells you what it does. It's a string view, meaning it views a string. And their documentation is world-class. The queue string view provides a unified view of a UTF-16 string with read-only subset of the queue string. What does all that mean? We can dive into the details and take a look and get a fairly lengthy explanation, but I can summarize it with this nice graphic here. So a queue string is really a sequence of zero or more because it can be empty of queue cares. And you can add, remove, and modify all you want, but that's the problem. You can add, remove, and modify, do anything you want to this. It's just the Wild West. You can do whatever you want. A string view, on the other hand, is designed to view that but not modify it. And to that end, it doesn't actually own the queue string or the sequence of queue cares. So it just kind of sits over the top of it like this. And you can read the entire string, or if you wanted to, you could read just part of it. Let's dive in and take a look. The first thing I want to touch on here is copy and modification issues. I have two queue strings. We're going to use both of these, but let's just hyper focus on one of these for now. Now remember, a queue string is something we can modify. So I'm just going to go in here, let's make a simple function. Let's call read me or actually let's call it read name, make it a little bit more descriptive there. Now to do this, we want to say queue string name. Notice what we're doing here, we're creating a copy. So if this was a large queue string, we are now duplicating our memory and slowing our application down. Remember, copy is slow. Just kind of get a magic marker and write that right on your computer screen copy is slow. That's part of why we use C++ because we want the speed. The other problem we have is we could do something like this. See what we're doing here. Yes, what's happening? That's right. We are modifying the copy of the string. Ooh, that could be bad. Let's go ahead and say queue info. And let's just say changed. And I'm sure if you were paying attention during C++ class when you're talking about scope, you know exactly what is about to happen here. So we are going to call that. Reading. Let's call that with our first name. And then let's go ahead and pump out the original. Notice the order. We're modifying it and then displaying the original save run. Let's see what happens. All you C++ gurus know exactly what's going to happen. We changed it to Mr. Brian, but the original is still unchanged. Okay, that's because we're working with a copy, not a big deal here. But again, a copy slow because if this string was huge, it would take a long time. So someone else is going to inherit this code and come in here and go, ah, I'm going to speed this up. What have we just done? Address of, okay. Address of is access of. So what we're really doing here is we're giving them full access to this variable. Now what's going to happen if I save and run this? Notice we don't get any compile errors or warnings, but now it has actually changed. So, well, yes, our little read name function now actually modifies it. That's a big no, no, and that could have some undesired consequences on your application. So that is why the string view exists to take away all of this complexity. So the string view exists because we want read only and no copy, but that's not really the case. We're going to copy the string view, but not the string itself. Let me go ahead and demonstrate that. So I'm going to grab this and we're going to modify it. So we're going to call this a read only and let's get rid of that. We're going to say Q string view. Notice how immediately we cannot modify it. Q string view has a lot of the simple functions like including parsing and things like that. We're going to demonstrate that later in this video, but it does not allow you to modify the underlying string. So let's go ahead and get rid of that and let's put this here. I'll say name, but notice what's happening here. It's just, well, it's copying and it's really not a big deal. So what we can majorly take away from this is because the string view is being copied, not the Q string, this will be much, much faster. To demonstrate this, let's go ahead and do this. I'm going to say data and then let's go ahead and pump out the name. Then down here, let's go ahead and say, I grabbed this whole thing. Just copy and paste. It's my buddy today. First name data and then let's go ahead and say first name. Then let's go ahead and call that read only. Just want to very simply demonstrate what's going on here. So what data is going to do, we highlight this and F1 on the keyboard. Returns a pointer to the data stored in the Q string, meaning the pointer can be used to access and modify the characters. This is a little bit dangerous what we're doing up here. So someone could argue you actually have the pointer and you can modify it correct, but the Q string view itself will not let you modify it directly. But what I'm actually demonstrating is the address of that character does not change, meaning we are not copying the string. Let's demonstrate that. All right, so you see we have two addresses and they are identical because they're both pointing towards that little B right there. So the string exists off in memory and the Q string view is pointing to the string, but it doesn't actually make a copy of the string, which is why we can't modify it. So the beautiful thing about Q string view is that it's fast and it's read only, but it also has some built in parsing very, very similar to Q string. So now that you understand the API for Q string, working with Q string view is a breeze. Let's go ahead and demonstrate that. So I'm going to say, let's make another Q string. Let's call this full name. And this is going to be our first name plus, and I'm just going to make a space. And we want the last name. I'm sure you've done something like this before where you're just adding those in together and creating a completely new Q string. Now what I want to do is split this apart back into first and last name. So something like this. So I'm going to say for each, I'm going to say Q string view part. And you may be going, no, wait a minute. That means that individual part is also read only and you're absolutely correct. I'm going to say Q string view. And we want to get this thing from the full name. So we're using that string right here. And we're going to turn that into a view. And now we want to split this. Notice how this is returning a Q list of Q string views, meaning we have a list of read only views. So let's go ahead and split this based off the Q care. So we're just basically going through and we're making a string view out of our full name, splitting on a space. It's really not super hard, but we're going to get back a list of Q string views. We're calling parts that are all read only. And this is just actually very, very simple. The Q info. And I'm just going to say parts. So I know what we're viewing on the screen. Go ahead, save run and see what that looks like. So now we have successfully split it back into its individual strings. Even though these are string views, we cannot modify on what we can read the underlying string. This is actually very, very cool. Now from here, we can actually do something. And I'm just going to put this here. I absolutely love you guys, but data types can get a bit annoying with this. And let me just demonstrate what I mean. So I'm going to say, if the part not starts with, and I would love to just give it a string, but instead I have to do a Q string view, Latin one string or a Q care. So if I wanted to just say, if it started with the first name, our string up here, I can't do that. It's going to just gripe and complain. That may change in future versions, but said I have to do a Q string view from our Q string. Not a big deal, but it's just a minor hassle, especially if you're just learning this. And we're just going to say cute. And I want case insensitive, which we talked about from the last video, which basically says it simply doesn't care. And let me fix that little misspelling right there. Now that we have this, we can just say, okay, you info. And I just want to know that we actually detected first name. You're that annoying little yellow window there. And now we're just going to call our read only function like we've called before. And I only want part of that first name. So this is what I mean by it can get a little bit annoying here. So now I need to go you string view. Major takeaway is Q string view likes to work with Q string view. They haven't really added in a bunch of other features. I suspect yet that's probably coming. You can of course always inherit the Q string view and make your own version of it. So now I want from the first to the third just because why not. The major takeaway here is we have a lot of the parsing functionality from Q string baked right in the Q string view. For example, we are splitting. We're checking to see if it starts with we're calling a mid and getting a portion of that. It's actually very, very simple to work with once you understand the Q string API. See first name detected and then Raya. That's not even my abbreviated name. So I would have to play with the offsets there of one and three, but you understand what's going on. The major takeaway from this video is that Q string view is fast. Why? Because we're not copying the string, but it's also read only. So it helps protect you, the developer from well yourself. 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.