 Hey everybody, this is Brian, and this video is going to cover what you can expect when you try porting your code from Qt 5 to Qt 6. Now they have a ton, and I mean a avalanche of documentation out there, and yes, if you have the time and the patient's definitely read through it, but if you're like me, you're just going to put your code through it and see what works and what doesn't, and that's exactly what this video is. It's an exhaustive look at what you can really expect if you take just the average typical code and try to build it. So this is not an in-depth look at everything new at Qt 6. These are the roadblocks you're going to encounter taking your existing code base and moving it to Qt 6. So first off, there is a lot of deprecation between 5.15 and 6, I mean a lot. They're actually really good at backwards compatibility, and I gotta really, you know, give them a round of applause, because most things just work right out of the box. And that's actually kind of interesting because if you look at this, there's a lot of obsolete classes, and if you look at the removed modules, you'll see they removed a lot, and you're going to panic because you're going to go, wait, I need charts, I need Bluetooth. But if you go into the new modules, you see they're in there. So really under the hood, this is, I don't want to say a complete rewrite, but they did a lot of housekeeping on this. So the monumental effort for sure, and I'm actually surprised how much code actually out of the box works as expected. So the biggest downfall for me was actually supported platforms. My virtual machine that I do my recording in was a version behind, which not a big deal. It was just a big bummer right out of the gate. And I did some videos on how to compile Qt from source and how to install it, and I actually did a whole video on how to set up a virtual machine using virtual box. So if your current operating system is not up to speed, you can just set up a virtual box and run it from there. It actually works really, really good on a virtual machine as you're about to see. Some other major takeaways is they're moving from C++ 11 to 17. I had read a document somewhere, I don't remember where, but I read it somewhere on the internet that 17 was going to be mandatory, but actually it wasn't when I built my first Qt 6 project. The other caveat is they are switching from Qmake to CMake. And if you are like me and you just love Qmake, you're like, why? It's just probably because it's a royal pain for them to maintain and CMake has become the industry standard. So CMake, once you get your head into it, really is not super hard. I'm going to pause right here and say, Qmake is not magically disappearing. So don't panic. You can still use Qmake, but CMake is now the preferred build system. They are no longer actively developing Qmake. You can still use Qmake, it's just not actively being developed. So if you're starting a new project, definitely start over with CMake. So what are we doing in this specific video? Well, I'm taking all the code that I did for my Udemy tutorials. We're talking about Qt Core Beginners, Intermediate, Advanced, QML, Widgets and Design Patterns. I mean, this is hours and hours of code and a huge amount of code from my YouTube channel. There's all Python there, but I've got literally years of Qt videos out here. So I've taken all that and I've compiled it and tested it. And that's what we're going to look at in this video is what works and what doesn't work. Quick note before we dive into the code. This is a virtual machine. It is just Linux Mint, the newest version. It is supported by Qt. There's virtually nothing installed other than Visual Studio Code. I had Python scripts running on this and Qt. So let's just crack open Qt here. And I'm going to go to about Qt Creator. This version is 4.14 based on Qt 5.15.2. Now, you may be going, wait a minute, I thought we were going to talk about Qt 6. Well, we are. But I'm highlighting this for a specific reason. Qt Creator, the IDE, is usually the last thing to get updated. So you may notice things right out of the bat, like IntelliSense or some sort of script just isn't going to work the way you would expect it to. Because Qt Creator itself may still be looking for things based off Qt 5. Most things, however, we were very forgiving and just worked right out of the box. Also under tools options, make sure that you have desktop Qt 6 installed. I'm using 6.0.0 on GCC 64-bit. This is actually just straight out of the box, just worked. I actually liked it. And final note, before we dive into the code, these will be CMake projects. So if you're not used to CMake, this is the general structure here. There is this CMakeList.txt and again, if you're not used to CMake, this probably looks like ancient Egyptian algebra and completely foreign to you. Basically this little bit here sets the project name. That project name gets used over and over again, for example, right here you have this CMake project name. So really all we're doing is saying take the directory name and use it as the project name. In this case, Qt CB11-3. And ironically, if you take that name and look out on GitHub, in my GitHub repositories, this would be the actual source code for the Qt 5 version. So if you want the older version of the code, you can go find it out on GitHub. I am going to re-record all of my videos starting from scratch at Qt 6, but it's going to be a massive undertaking. All right. So moving along, some other things you should be aware of is that they do have some compatibility here with Fine Package. You're looking for 6 and 5. And there is a backwards compatibility module. So if they've taken an API out, there is a module where they say it has the code. And I'll be honest with you, it's been hit or miss working for me. Sometimes it works. Sometimes it doesn't. It just is what it is. Okay. The first issue I really ran into was using Q-variant from QString. Let me explain a little bit here. So when we look at our code, I have the Qt 5 version of the code and the Qt 6 version of the code. So basically we're saying, test your set property. So we're working with Qt property system and we're setting message to hello world. It's just a string. Makes sense, right? And if we go out here and look at this, I've made no changes to the class. So we're really just saying this little Qt property message, we're going to read-write and then we have this notify. So it's message or set message, which of course is just a Qt string. This absolutely stopped working in Qt 6 and I had to convert it to a Q-variant. Makes sense now that I've wrapped my head around why that is because the property system wants to work under the hood with a Q-variant and it's not going to automatically cast that to a Q-string. So under the hood, it's going to say Q-variant to string. Some minor changes to the date time. Here I've got the 5 code and then we've got the 6 code underneath it. So for example, in Qt 5, you'd say Qt Date Format System Local Date, that has gone the way of the dinosaur. Now you would say something like Qt Date Format, either ISO date, RFC or text. Generally what I would stick with is text, but if you need one of those others, they're there. So let's go ahead and run this and see what it looks like here. So it works as expected. You just got to be aware that if you try to use the system local date, you're going to have a bad time and just simply won't compile. All right. If you've been using Qt Link List, well, you're going to have a bad time. So Qt Link List, it's just going to simply say File Not Found. And it really doesn't give you a rhyme or reason. You're trying to figure out what's going on here. You're going to have to go into your CMake List and do a little bit of surgery. Don't worry, it's not super hard. You're going to add the Core 5 compatibility module. And I'm just going to do a little copy and paste action here. Let's go ahead and save that. And once you do, as soon as the IDE figures out what's going on, suddenly that error goes away. We can now build and we can run. So I guess the major takeaway for this segment is when in doubt, try adding that compatibility module into your CMake and see if it just magically pops back to life. However, doing so, this is a Band-Aid approach, meaning don't rely on that because this module could stop being supported at any time. This is Qt's friendly way of saying, hey, we don't want you doing this anymore. We're probably not going to support it in future versions. Another major hurdle if you work with any sort of massive text processing is going to be Qtex codec. It's just simply file not found. So let's go ahead and go into our CMake and let's try to add the Core 5 compat and see what happens. Let that figure out what it's doing and let's jump back to our source. Magically, it reappears. Let's see if we can give it a good build and hopefully fingers crossed. We get a successful build and it will run. So another hats off to our compatibility module. It just does seem to work again, though, however, Qtex codec is going the way of the dinosaur. Most people are working with UTF-8 nowadays, so it really doesn't matter that much. And you can always use Qstrings built in to UTF-8 function. I think the thing that's gotten me the most is some of the subtle changes you don't really think about. So for example, the humble Qstring. In Qt 5, Qstring append and then we're appending an int worked just fine. It would actually do it and it would convert it to a character for us. However, in 6, I have to say Qstring append and then actually cast it. So just be aware you're going to run into those little subtle maddening issues. When in doubt, if you get some sort of weird error, try to cast it yourself. Okay, here was an odd one. I have a simple logger when I say simple for some newbies. It may not be super simple, but basically it's just a Q message log context or a message handler. So every time you do like a Q debug or Q info or Q warning or something like that, it's going to intercept it and do something with it. Preferably like dump it to a file or something. Well, the weird thing was, Endel stopped working. I went, wait what? So I put STD, colon, colon, Endel and I'm still getting this. Whereas just there's no overload for it, it's just gone. So it just doesn't work anymore. Okay, super simple to fix this. Just say something like do that and let's go ahead and give it a build. That'll probably generate a warning though because I've got two of them in one. It was just kind of mystified me why that was suddenly an issue. But for some reason, it just doesn't like to take Endel anymore. So that's probably something the compatibility module would fix, although I haven't really deep dived into it just to make sure. Let's go ahead and check this out and make sure now it is working as expected. So if you're using Endel, you may have a bad time. Just kind of forewarn about that. All right, if you use Pimples or D pointers to implementations, you may see a subtle break in your code. This kind of just messed with me for a moment here. I had to figure out what the heck was going on. But basically I was doing a lesson on this and in Q5, this worked just fine. Where we were saying Q info and then we had this D pointer. Well, now it is a Q scope pointer. So we have to do something like this. This D pointer data, it wasn't doing it automatically, it's now a Q scope pointer. Minor little change, but still it's just one of those things that will just cause your code not to compile. Here's a minor change to QSYS info that may make your application not compile. In the Q5, you could say like sysmac version or syswindows version. Those just simply don't exist anymore. When I say don't exist anymore, mind you, I'm running on a Linux box. So I haven't really deep dived under the hood. Something like this may be going on where it just simply doesn't exist because I'm on Linux. But everything else just works as expected. So minor change, just keep that in mind when you're building your projects. Another minor little gotcha here I ran into was with the QXML stream reader. Basically, I had just a stream reader that was reading a very simple XML file and it just broke and I mean completely stopped. And I had to figure out what was going on here. So stream name used to be a string. Now you have to do a stream name, which is a string view, two string. So what is a string view? If you're not familiar with this, it came in some of the later versions of Qt. But basically a Q string view is a class that provides a unified view of a UTF 16 string in a read only subset, meaning you cannot modify this thing. It's read only. Why? Well, because it's faster and because it's safer. Now that you cannot modify it, it means your code's probably not going to crash. But just understand you now have to do the two string or it simply won't work. So far, most of these have been changes where you're like, why did they do that? But you know what, there's actually some good news. So if you've worked with sockets before and you've tried connecting to the abstract socket, socket error, it's been a royal pain in the past. So for example, I have this code for Qt 5, you have to say connect and then they socket and then you have to do a Q overload to an abstract socket, socket error of and then I mean, it just looks horrible. Royal pain that's super streamlined. Now you just do this just like a normal signal slot. So I couldn't figure out when I went to compile this why I was getting an error. It just said it didn't exist. But now you have this QTCP socket error occurred. I'm just going to connect that to my error slot and life is good. This next one is for you advanced programmers. This is the QSSL socket. There are some changes to this. So for example, in Qt 5, you used to be able to say response append and then blah, blah, blah. This was more of a Q string where Q string number you have to do the data. When I say data, what are we talking about here? Q byte array, we now cannot just take a byte array and shove it into a string. We have to say to ETF 8 right there will not work unless you do that. Now also to do all the way down here. All right, we talked about the error occurred. We can now just connect to that like a normal signal slot without any overloads or anything like that. But also what I ran into was the set protocol. Suddenly TLS V1 SSL V3 does not work. I had to set it to something totally different. So just be aware of that. There are some underlying protocol changes. One thing that kind of just came out of nowhere was a small change to the Q network access manager. This one kind of stumped me at first because I wasn't expecting it. And I only caught it because I was running a bunch of automated tests using a Python script, basically in Qt 5, you could say something like Q network access manager network accessibility. And you could monitor for that change. It's just simply not there anymore. I couldn't find it. So I didn't really deep dive into it because I don't use it very much. But if you're using this, well, you may have to find a different signal to backbone off of or find a different way. I did not go out and check the compatibility module. It may actually come and save the day for you. But just be aware there is some tweaking going on in the background for the Q network access manager. Most modern programs are, well, multi-threaded and high performance. So you're going to use some sort of multi-threading or a thread pull. Or if you are like me, you like using Qt concurrent because it uses Q thread pull and it hides all that complexity. So you don't have to worry about it. There's a minor change, but it will just make you scratch your head when you try to compile your code. So the old way of doing it is you're going to say Qt concurrent run and then the object along with the function and then the arguments. The new way is now backwards. So it is the function, the object, and then the arguments. And then it just works as expected. It just for a moment there, you're like, what? But it makes sense now because they're going from bigger to smaller. When I say bigger to smaller, they're going function, object, argument. So if you can burn that in a memory, function, object, arguments, you'll then figure out why you have all these compilation errors when you come to Qt concurrent. Another surprising one that really kind of threw me for a loop was run in an automated test and I just kind of looked at the screen and went, huh, what in the heck is going on here? So this simple example, and it maybe it wasn't the best example in the world was a Q-runnable. And inside the runnable, we're doing some basic things. And this right here is what blew up. We're saying Q string S print F and it just completely exploded and refused to work. I was like, what? So now you have to do Q string A S print F and then it works. And notice minor formatting change. Once you do that, because it didn't know what the zero was in the format. Once you do that, it works just fine. It's just S print F is gone. So you have to use a S print F now. OK, unfortunately, I do have some bad news. If you use Q state machine, it hasn't been fully moved to Qt 6 yet. And this one kind of misfied me and I had to do some creative Googling to figure out what was going on here. So in our C make, if I go ahead and try and build this, you're going to get this Q state machine, no such file or directory and try as I might just couldn't find it. So I loaded up the actual Q make file and I, you know, switched it from 11 to 17 and made sure it was on Qt 6 kit and all that other stuff. And then when we go to build same issue, Q state machine, no such file or directory, it just simply hasn't been moved to Qt 6 yet. So if you need Q state machine, Qt 6 might not be ready just yet. Rumor has it when I say rumor, it was out in a forum somewhere. So I don't really trust the source, but they were talking about Qt 6.0.1. So very, very soon. But of course, world events being what they are, it could be later than that. The first QML application, I loaded up into Qt 6. I was just like, OK, if anything's going to break, this is what's going to break it because I have a C++ class that I'm pushing over into QML land. And I'm doing that you guessed it by using the Q register type. And I thought, for sure this will break it. But immediately I get this warning set attribute Qt AA enable high DPI scaling. Notice how that is now going away. So be careful with that one. But that's actually not what broke the application. The application compiled, but then it failed to run. And this is going to be an intrinsic problem you'll have with QML. If you're doing any sort of automated compilation, it will compile just fine because the C++ code works. But when it goes to run, it'll have a hard fail. And QML just won't run. You'll get some exit code, I think of like 255 or something like that. The Achilles heel of this was that dialogues was moved from cute, quick dialogues, one, three to cute labs, platform one, one or one, oh. And you have some minor changes in the dialogue. So let me kind of scroll down and find them here. Select multiple no longer exists, select existing no longer exists. And you now have to set a file mode, whether it's file, dialogue, save file or open file, once you do that, everything pretty much works as the old cute five versions did. It's just kind of minor tweaking around that you got to do with some of your QML code. So if you're using dialogues by or beware, you're going to have to make some small changes. Another thing that got caught into the compatibility black hole is, well, regular expressions. I was using this simple validation example. When I say simple, it was really anything, but, um, and it uses Q reg expression under the hood. And I had to change that to Q regular expression, but that only worked after I went out and added the core five compatibility. And we've kind of covered how to do this. And remember that when you add this, this is not like an instant fix. You now need to start looking for the correct way or a completely different way of doing things. So if you're working with regular expressions, just know, you're probably not going to be able to use the old way of doing things. If you're using widgets, one thing that's going to come and bite you is Q close event. It's pretty common practice that when the window is closing, you're going to say, Hey, user, did you save your file? If not, let's go ahead and ask if you want to save it, blah, blah, blah. It just stopped working and it wouldn't compile. So basically it was a super easy fix. I just had to include Q close event, but just know if you're working with Q widgets, it's not actually included automatically anymore. You've got to include it yourself. Another one for Q widgets is the Q list widget item in Q five. You have the item is tri-state that doesn't exist anymore. You have to do item is auto tri-state and it's a little confusing. So if you don't know or even have a clue what I'm talking about, let's run this and let's see. So this is a very, very simple application I did just as a demonstration that allows you to check or uncheck or have what's called a tri-state. So for example, we can say a couple of new items and let's go ahead and select these and let's set the state to checked. And then we can say unchecked or we could do partially. That's the tri-state where you have three different states. So if you try to do the old way, you're going to have a bad time is really what I'm getting at here. When in doubt, item is tri-state is gone and you need to do the item is auto tri-state. Another widgets was the windows flag. It's pretty, pretty commonplace that when you load a window, you want to set whether it has a min, max button, context help and all that fun stuff. Well, traditionally in Q five, I would say Qt windows flags, flags equals zero. And that right there came back and bit me. And I don't think that is a modification with Qt, but probably from switching from C++ 11 to C++ 17 simple fix. You just simply don't set the value and then you or equal it all the way through to whatever flag you currently want. OK, a super confusing one is back in QML land. And let's go ahead and give this a good build just to show you what I mean here. So we're going to rebuild this bad boy and it's going to just churn away and it's going to go ahead and do its build and we're going to get a successful build with one warning. And when we look at the warning, we get that naval high DPI scaling is deprecated. Don't really care. But when we go to run, no runny. This is one of the confusing bits. And you get this main QML cannot assign object for menu bar property of type Qt quick item as a former or neither. What, what in the heck? So when we go out here, this is what I mean by it gets super, super confusing. Again, I had to switch dialogues and we covered that in a previous section, but down here, I have all these actions and then this is what it's complaining about. The menu bar no longer works. And I've actually gone out to the website and copy and pasted the code from the website for Qt six zero into here. And the menu bar just will not work. I just can't get it to work even with a compatibility module. So I'm going to tweak around and play around with this little bit and try to figure out what the heck is going on here. I have a sneaky suspicion. It's probably some weird change. I just haven't spotted yet. So if you know the answer, drop a comment below. I'd love to know what it is. Save me a few hours of figuring it out. 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.